CSS chapters

Chapter 3 of 17

Selectors and declarations

Try this in our CSS Compiler →

The idea

A selector appears before braces; declarations inside use property: value pairs. Class selectors start with a dot and id selectors with #. Comments use /* ... */. A misspelled property is ignored rather than interpreted as a variable or a new feature.

Worked example

h1, h2 { line-height: 1.2; }
.notice { border: 1px solid teal; padding: 12px; }

What to check

The comma selects two independent groups. A space between selectors instead represents a descendant relationship.

Practice task

Create a rule for paragraphs inside an article, then compare it with a rule targeting every paragraph.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on