CKTIS / CSS
CSS syntax: rules and declarations
Learn the distinction between a CSS qualified rule and a declaration: the selector identifies elements, while declarations inside the block specify properties and values. Also see how the browser handles an invalid value.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
selector { property: value; property: value; }The term CSS qualified rule / declaration covers two different syntax levels. A qualified rule has a prelude and a {} block. In a style rule, the prelude is a selector list identifying elements. Not every qualified rule is a style rule: rules inside @keyframes have a different meaning.
A declaration has a name, a colon :, and a value. In a style rule, it declares a property, such as color: blue. Semicolons ; separate declarations; the final one before } is optional, but including it makes later additions safer. Indentation improves readability; it does not replace separators.
An at-rule starts with @, such as @media, and is not a qualified rule. Depending on context, blocks can contain declarations or nested rules; do not assume every CSS block contains only declarations.
In the example, .sample is the selector and color: blue is a declaration. The invalid value in color: not-a-color causes that declaration, not the whole rule, to be discarded. The expected result is blue text and a black border. This does not make arbitrary syntax errors harmless: a missing semicolon can merge adjacent declarations and cause the parser to discard them.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>CSS syntax example</title>
<style>
.sample {
color: blue;
color: not-a-color;
border: 2px solid black;
}
</style>
<p class="sample">CSS syntax</p>
</html>Result
The paragraph displays “CSS syntax” in blue with a 2px solid black border.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.