The CSS syntax defines how we write rules to set the style of HTML elements. Understanding the syntax is essential for the effective use of CSS.
A CSS rule consists of a selector and a declaration block. The declaration contains properties and their values, which define the style of the element.
With selectors we choose which HTML elements we apply the rules to. The most common ones are element, class, and id selectors.
The element selector directly refers to the HTML element by name, for example every <p> element.
The class selector applies to elements with a specific class attribute and always starts with a dot.
The id selector applies to an element with a unique identifier and always starts with a hash (#).
A CSS rule can contain multiple declarations that precisely define the appearance of the element.
Selected: #id (1/3)
/* Choose the correct selector type */
#id {
background-color: yellow;
}
Move the slider to set the value, then check your answer.
The correct use of syntax helps to write clean and easily maintainable CSS code.
Please sign in to ask Lara about CSS Syntax.
Select Language
Set theme
© 2025 ReadyTools. All rights reserved.