CSS Syntax

CSS Syntax

The CSS rule-set (rule-set) is composed of selectors and declaration blocks:

CSS Selector

The selector points to the HTML element you need to style.

A declaration block contains one or more declarations separated by semicolons.

Each declaration contains a CSS property name and a value, separated by a colon.

Multiple CSS declarations are separated by semicolons, and declaration blocks are enclosed in curly braces.

Example

In this example, all <p> elements will be centered and have red text color:

p {
  color: red;
  text-align: center;
}

Try It Yourself

Example Explanation

  • p Is in CSSSelector(It points to the HTML element to be styled: <p>).
  • color Is a propertyred Is a property value
  • text-align Is a propertycenter Is a property value

In the next chapter, you will learn more about CSS selectors and CSS properties.