docs.rodeo

MDN Web Docs mirror

Value definition syntax

{{CSSRef}} 

CSS value definition syntax, a formal grammar, is used to define the set of valid values for a CSS property or function. In addition to this syntax, the set of valid values can be further restricted by semantic constraints (for example, for a number to be strictly positive).

The definition syntax describes which values are allowed and the interactions between them. A component can be a keyword, some characters considered as a literal, or a value of a given CSS data type or another CSS property.

Component value types

Keywords

Generic keywords

A keyword with a predefined meaning appears literally, without quotation marks. For example: auto, smaller, or ease-in.

CSS-wide keywords

All CSS properties accept the keywords inherit, initial, revert, revert-layer, and unset. They are not shown in the value definition and are implicitly defined.

Literals

In CSS, a few characters can appear on their own, like the slash (/) or the comma (,), and are used in a property definition to separate its parts. The comma is often used to separate values in enumerations, or parameters in mathematical-like functions; the slash often separates parts of the value that are semantically different, but have a common syntax. Typically, the slash is used in shorthand properties; to separate components of the same type, but belong to different properties.

Both symbols appear literally in a value definition.

Data types

Basic data types

Some data types are used throughout CSS and are defined once for all values in the specification. Called basic data types, they are represented with their name surrounded by the symbols < and >: {{CSSxRef("&lt;angle&gt;")}} , {{CSSxRef("&lt;string&gt;")}} , …

Non-terminal data types

Less common data types, called non-terminal data types, are also surrounded by < and >.

Non-terminal data types are of two kinds:

Component value combinators

Brackets

Brackets enclose several entities, combinators, and multipliers, then transform them as a single component. They are used to group components to bypass the precedence rules.

bold [ thin && <length> ]

This example matches the following values:

But not:

Juxtaposition

Placing several keywords, literals, or data types, next to one another, only separated by one or several spaces, is called juxtaposition. All juxtaposed components are mandatory and should appear in the exact order.

bold <length>, thin

This example matches the following values:

But not:

Double ampersand

Separating two or more components, by a double ampersand, &&, means that all these entities are mandatory but may appear in any order.

bold && <length>

This example matches the following values:

But not:

[!NOTE] Juxtaposition has precedence over the double ampersand, meaning that bold thin && <length> is equivalent to [ bold thin ] && <length>. It describes bold thin <length> or <length> bold thin but not bold <length> thin.

Double bar

Separating two or more components by a double bar, ||, means that all entities are options: at least one must be present, and they may appear in any order. Typically this is used to define the different values of a shorthand property.

<'border-width'> || <'border-style'> || <'border-color'>

This example matches the following values:

But not:

[!NOTE] The double ampersand has precedence over the double bar, meaning that bold || thin && <length> is equivalent to bold || [ thin && <length> ]. It describes bold, thin <length>, bold thin <length>, or thin <length> bold but not <length> bold thin as bold, if not omitted, must be placed before or after the whole thin && <length> component.

Single bar

Separating two or more entities by a single bar, |, means that all entities are exclusive options: exactly one of these options must be present. This is typically used to separate a list of possible keywords.

<percentage> | <length> | left | center | right | top | bottom

This example matches the following values:

But not:

[!NOTE] The double bar has precedence over the single bar, meaning that bold | thin || <length> is equivalent to bold | [ thin || <length> ]. It describes bold, thin, <length>, <length> thin, or thin <length> but not bold <length> as only one entity from each side of the | combinator can be present.

Component value multipliers

A multiplier is a sign that indicates how many times a preceding entity can be repeated. Without a multiplier, an entity must appear exactly one time.

Multipliers cannot be added and have precedence over all combinators.

Asterisk (*)

The asterisk multiplier indicates that the entity may appear zero, one or several times.

bold smaller*

This example matches the following values:

But not:

Plus (+)

The plus multiplier indicates that the entity may appear one or several times.

bold smaller+

This example matches the following values:

But not:

Question mark (?)

The question mark multiplier indicates that the entity is optional, and must appear zero or one time.

bold smaller?

This example matches the following values:

But not:

Curly braces ({ })

The curly braces multiplier, enclosing two integers separated by a comma, A and B, indicates that the entity must appear at least A times and at most B times.

bold smaller{1,3}

This example matches the following values:

But not:

Hash mark (#)

The hash mark multiplier indicates that the entity may be repeated one or more times (for example, the plus multiplier), but each occurrence is separated by a comma (‘,’).

bold smaller#

This example matches the following values:

But not:

The hash mark may optionally be followed by curly braces to indicate how many times the entity repeats.

bold smaller#{1,3}

This example matches the following values:

But not:

bold smaller#{2}

This example matches the following value:

But not:

Exclamation point (!)

The exclamation point multiplier after a group indicates that the group is required, and must produce at least one value; even if the grammar of the items within the group would otherwise allow the entire contents to be omitted, at least one component value must not be omitted.

[ bold? smaller? ]!

This example matches the following values:

But not:

Bracketed range notation ([min,max])

Some types can accept numeric values within a certain range. For example, the column-count property can accept an integer value between positive 1 and infinity, inclusive. The corresponding syntax looks like this:

<integer [1,∞]>

Any value outside this specified range causes the whole declaration to be invalid, therefore the browser will ignore it.

The bracketed range notation [min, max] indicates an inclusive range between a min and max value. This notation is used in numeric type notations and can include units, e.g. <angle [0,180deg]>. Positive and negative Infinity (-∞ and ∞) must not have units specified. Types specified in units can have zero values specified with or without units, for example <time [0s,10s]> or <time [0,10s]>.

Here are some more examples:

Summary

Sign Name Description Example
Combinators
Juxtaposition Components are mandatory and should appear in that order solid <length>
&& Double ampersand Components are mandatory but may appear in any order <length> && <string>
|| Double bar At least one of the components must be present, and they may appear in any order. <'border-image-outset'> || <'border-image-slice'>
| Single bar Exactly one of the components must be present smaller | small | normal | big | bigger
[ ] Brackets Group components to bypass precedence rules bold [ thin && <length> ]
Multipliers
No multiplier Exactly 1 time solid
* Asterisk 0 or more times bold smaller*
+ Plus sign 1 or more times bold smaller+
? Question mark 0 or 1 time (that is optional) bold smaller?
{min,max} Curly braces At least min times, at most max times bold smaller{1,3}
# Hash mark 1 or more times, with each occurrence separated by a comma (,) bold smaller#
! Exclamation point Group must produce at least 1 value [ bold? smaller? ]!
Ranges
[min,max] Numeric bracketed range Specifies a numeric range <integer [0,∞]>

Specifications

{{Specifications}} 

See also

In this article

View on MDN