Formal value definition syntax
Definition and purpose
CSS value definition syntax describes which tokens a property accepts. Angle-bracket names denote types or grammar productions, while literal keywords are written as themselves. The grammar is documentation, not CSS to paste into a declaration.
Ordered repetition
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { padding: 4px 8px 12px 16px; } </style> </head> <body> <div id="a">Panel</div> <div id="b">Other</div> </body></html>Four values follow top, right, bottom, left order.
Syntax and mental model
A vertical bar means choose one; || means one or more alternatives in any order; && requires all components in any order; juxtaposition requires sequence. Brackets group terms. ? means optional, * zero or more, + one or more, # a comma-separated repetition, and {1,4} a count range. A type range such as <length [0,∞]> restricts accepted values. The grammar for padding accepts one to four nonnegative length-percentage values.
Unordered components
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { border: solid red 3px; } #b { border: 3px solid red; } </style> </head> <body> <div id="a">Panel</div> <div id="b">Other</div> </body></html>Both orders are allowed by the border grammar.
Common mistakes
Do not confuse || with exactly one alternative. A literal negative padding is invalid, although a calculation may be clamped according to range-checking rules.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Other dimensions and URL values, Semantic tokens and themes. Next lesson: Typed arithmetic and compatibility.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Formal value definition syntax — knowledge check
Five questions on formal value definition syntax.
What does A | B mean?
What does A && B require?
What does A || B mean?
What does a # multiplier mean?
What does <length [0,∞]> require?