A CSS declaration associates a CSS property with a CSS property value, optionally marked important. In source syntax, a colon separates the name from the value, and semicolons separate declarations in a list. For example,
color: red declares a foreground color; the surrounding CSS selector determines which elements the rule addresses.[ref]CSS Syntax Module Level 3 by World Wide Web Consortium. Syntax Description; declaration definition: name, component-value list and important flag
The rule
p { color: red; width: 20px; } contains two CSS declarations. The braces enclose the block of CSS declarations. !important in color: red !important sets the declaration's priority flag; it is not part of the color value used to paint the text.Parsing a declaration is only one stage of validation.
width: blue has the superficial name-colon-value form, but blue is not a valid width value, so it does not supply a usable width declaration. An unrecognized property name is likewise not a way to create an arbitrary new built-in styling property. A preceding valid declaration can remain effective when a later invalid one is discarded.[ref]CSS Syntax Module Level 3 by World Wide Web Consortium. Error Handling and parsing declarations; distinction between generic syntax and property-specific interpretation
When several valid declarations address the same element and property, the CSS cascade decides among them. For ordinary declarations with equal prior cascade priorities and equal CSS specificity, a later declaration wins. The declaration expresses a candidate value; its presence in a file alone does not prove that the candidate becomes the element's final presentation.
Articles by others on the same topic
There are currently no matching articles.