CSS (Cascading Style Sheets) is a style language used to define the appearance and layout of HTML documents. It lets you separate the document's content from its visual presentation, making code maintenance easier and more efficient.

CSS works by selecting HTML elements and applying style rules to those elements. Style rules can define properties such as color, font, size, spacing, position, and more.

To use CSS in an HTML document, it is necessary to create a separate file with a .css extension, which contains the style rules. This file must be referenced in the HTML document through the tag <link>.

Basic CSS syntax consists of a selector, which indicates the HTML element to be styled, followed by a block of style declarations, delimited by braces. Each style declaration consists of a property and a value, separated by a colon and terminated by a semicolon.

For example, to set the background color of a <div> element to red, the CSS code would be:

div { background-color: red; }

There are several types of CSS selectors, which allow you to select elements based on their class, ID, type, hierarchy, and other criteria. In addition, you can use pseudo-classes and pseudo-elements to style elements based on their state or position.

CSS also supports the use of units of measurement, which can be fixed (like pixels) or relative (like percentage or em). Relative units are especially useful for creating responsive layouts that adapt to different screen sizes.

In short, CSS is a fundamental tool for creating well-structured, visually appealing web pages. With it, it is possible to separate the visual presentation from the document content, facilitating the maintenance and updating of the code. In addition, CSS offers several options for selectors, properties and units of measurement, allowing you to create flexible and responsive layouts.

Now answer the exercise about the content:

_What is the role of CSS in an HTML document?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image CSS syntax

Next page of the Free Ebook:

2CSS syntax

2 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text