Cyber Code Academy
Tutorials Academy Courses
Home / CSS / CSS Syntax and Selectors

CSS Syntax and Selectors

CSS rule structure

selector {
  property: value;
}

The selector chooses elements. A declaration contains a property and its value.

Common selectors

p { color: #333; }       /* element selector */
.notice { color: orange; } /* class selector */
#main-title { font-size: 2rem; } /* ID selector */
* { box-sizing: border-box; } /* universal selector */

Use classes for reusable styles. IDs should identify a unique element and are less reusable for styling.

Practice

Style all paragraphs, one class named notice, and one element with the ID main-title.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses