HTML (Hypertext Markup Language) is a markup language used to create the structure of a web page. It consists of tags that define various elements of a page, such as headings, paragraphs, links, and images. CSS (Cascading Style Sheets) is a language used to add style and formatting to HTML documents.
CSS works by selecting HTML elements and applying various styles to them. This can include things like font size, color, spacing, and layout. CSS can be applied to HTML documents in a number of ways, including inline styles, embedded styles, and external style sheets.
Inline styles are styles that are applied directly to an HTML element using the “style” attribute. For example, to make a heading red, you could use the following code:
<h1 style="color: red;">This is a heading</h1>
Embedded styles are styles that are included within the HTML document using the “style” element. For example:
<style>
h1 {
color: red;
}
</style>
External style sheets are styles that are defined in a separate CSS file and linked to the HTML document using the “link” element. For example:
<link rel="stylesheet" href="style.css">
Using external style sheets is often preferred because it allows for greater consistency across multiple pages on a website and makes it easier to make global changes to the design of a site.
CSS also allows for the use of selectors to apply styles to specific elements or groups of elements. For example, to apply a style to all headings on a page, you could use the following code:
h1, h2, h3 {
color: blue;
}
Overall, CSS is a powerful tool for creating visually appealing and consistent web pages.
