A CSS rule has two parts: a selector, and a declaration block wrapped in curly braces.
CSS
selector {
property: value;
property: value;
}- The selector points to the HTML element you want to style.
- Each declaration is a
property: valuepair, ending in a semicolon.
CSS
p {
color: #1f2937;
font-size: 16px;
}This rule selects every <p> element and sets its text color and font
size. Whitespace and line breaks don't matter to the browser — they're
there for readability. A missing semicolon before the closing brace is
usually forgiven, but always add one anyway; it saves you when you add a
second declaration later.
Grouping selectors
Comma-separate selectors to apply the same declarations to several of them at once, instead of repeating the block:
CSS
h1, h2, h3 {
font-family: sans-serif;
color: #111827;
}