A CSS rule has two parts: a selector and a declaration block.
h1 { color: blue; font-size: 32px; }
h1is the selector — which elements to stylecolorandfont-sizeare propertiesblueand32pxare values- Each
property: value;pair is a declaration, ending with a semicolon - Declarations sit inside curly braces
{ }
Tips
- You can write one declaration per line to keep code readable.
- CSS ignores extra spaces and line breaks.
- Property names are lowercase, with words joined by dashes:
background-color.
Example
Example — Rule with several declarations
HTML
<style>
p {
color: white;
background-color: #1f386b;
padding: 12px;
font-size: 18px;
}
</style>
<p>One selector, four declarations.</p>
All four declarations apply to every paragraph.
Try it Now »