# Value definition syntax

Revision Information
• Revision slug: CSS/Value_definition_syntax
• Revision title: Value definition syntax
• Revision id: 311443
• Created:
• Creator: teoli
• Is reviewed? Yes
• Reviewed:
• Reviewed by: teoli
• Is approved? Yes
• Is current revision? No
• Comment

## Revision Content

To define the set of valid values that a CSS property or function can take, a formal grammar is used, the CSS value definition syntax. Besides the syntaxic aspect, the set of valid values can be further restricted by semantic constraints (like, for a number, to be strictly positive).

The definition syntax describes which components are allowed and how they interact between them. A component can be a keyword, some characters considered as a litteral, or a value of a given CSS data type or of another CSS property.

## Component value types

### Keywords

#### Generic keywords

A keyword with a predefined meaning, such as auto, smaller or ease-in, appears litterally, without quote: e.g. auto, smaller or ease-in.

#### The specific case of inherit and initial

All CSS properties accept the keyword inherit and initial which are defined CSS-wide. They are not shown in the value definition, and are implicitly defined.

### Litterals

In CSS a few character can appear on their own, like the slash ('/') or the comma (','), can be used in properties to separate part of it. The comma is often used to separate several values in enumeration, or parameters in mathematical-like functions, the slash often separate different part of the value, allowing to define unambiguously. They appear on their own in a value definition.

### Data types

#### Basic data types

Some kind of data are used throughout CSS and are defined once for all. They are represented with their name surrounded by the symbol '<' and '>': {{ xref_cssangle() }}, {{ xref_cssstring() }}…

#### Non-terminal data types

Non-terminal data types are of two kinds:

• data types sharing the same name of a property, put between quotes. In this case the data type shares the same set of value than the property. This is often used in the definition of shorthand properties.
• data type not sharing the same name of a property. These data types are very close to the basic data types. They only differ in where the definition is set: in this case the definition is usually physically very close to the definition of the property using them.

## Component value combinators

### Juxtaposition

Putting several keywords, litterals, data types one of the other, separated by one or several spaces is called juxtaposition. Each juxtaposed entities are mandatory and should appear in that order.

bold <length> , thin

This example matches the following values:

• bold 1em, thin
• bold 0, thin
• bold 2.5cm, thin
• bold 3vh, thin

But not:

• thin 1em, bold as the entities must be in the expressed order
• bold 1em thin as the entities are mandatory; the comma, a litteral, must be present
• bold 0.5ms, thin as the ms values are not {{xref_csslength()}}

### Double ampersand

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

bold && <length>

This example matches the following values:

• bold 1em
• bold 0
• 2.5cm bold
• 3vh bold

But not:

• bold as both entities must appear in the value
• bold 1em bold as both entities must appear only one time
Note: juxtaposition has precedence over the double ampersand, meaning that bold thin && <length> describes bold thin <length> or <length> bold thin but not bold <length> thin.

### Double bar

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

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

This example matches the following values:

• 1em solid blue
• blue 1em
• solid 1px yellow

But not:

• blue yellow as an entity must appear at most one single time
• bold as it isn't a keyword allowed as value of any of the entity
Note: the double ampersand has precedence over the double bar, meaning that bold || thin && <length> describes bold, thin, <length>, bold thin, <length> bold, or thin <length> bold but not bold <length> bold thin as bold, if not omitted, must be positioned before or after the whole thin && <length> entity.

### Single bar

Separating two or more entities by a single bar, |, means that all entities are 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:

• 3%
• 0
• 3.5em
• left
• center
• right
• top
• bottom

But not:

• center 3% as only one of the entity must be present.
• 3em 4.5em as an entity must be present at most one time.

### Brackets

Brackets enclose several entities, composers and multiplier and transform them as a single entity. They are used to group elements to bypass the precedence rules.

bold [ thin && <length> ]

This example matches the following values:

• bold thin 2vh
• bold 0 thin
• bold thin 3.5em

But not:

• thin bold 3em as bold is juxtaposed with the entity defined by the brackets, it must appear before it.

## Component value multiplier

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

### Asterisk (*)

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

bold smaller*

This example matches the following values:

• bold
• bold smaller
• bold smaller smaller
• bold smaller smaller smaller and so on.

But not:

• smaller as bold is juxtaposed and must appear before the eventual smaller keyword.

### Plus (+)

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

bold smaller+

This example matches the following values:

• bold smaller
• bold smaller smaller
• bold smaller smaller smaller and so on.

But not:

• bold as smaller must appear at least one time.
• smaller as bold is juxtaposed and must appear before the eventual smaller keyword.

### 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:

• bold
• bold smaller

But not:

• bold smaller smaller as smaller must appear at most one time.
• smaller as bold is juxtaposed and must appear before the eventual smaller keyword.

### Curly braces ({ })

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

bold smaller{1,3}

This example matches the following values:

• bold smaller
• bold smaller smaller
• bold smaller smaller smaller

But not:

• bold as smaller must appear at least one time.
• bold smaller smaller smaller smaller as smaller must appear at most one time.
• smaller as bold is juxtaposed and must appear before the eventual smaller keyword

### Hash mark (#)

The hash mark multiplier indicates that the entity may be repeated one or more times (like the plus multiplier) but each occurence is separated by a comma (',').

bold smaller#

This example matches the following values:

• bold smaller
• bold smaller, smaller
• bold smaller, smaller, smaller and so on.

But not:

• bold as smaller must appear at least one time.
• bold smaller smaller smaller as the different occurence of smaller must be separated by commas.
• smaller as bold is juxtaposed and must appear before the eventual smaller keyword.

## Summary

Sign Name Description Example
Combinators
Juxtaposition Entities are mandatory and should appear in that order solid <length>
&& Double ampersand Entities are mandatory but may appear in any order <length> && <string>
|| Double bar At least one of the entities must be present, and they may appear in any order. <'border-image-outset'> || <'border-image-slice'>
| Single bar Exactly one of the entities must be present smaller | small | normal | big | bigger
[ ] Brackets Group elements to bypass the precedence rules
Multipliers
No multiplier Exactly 1 times solid
* Asterisk 0 or more times
+ Plus sign 1 or more times
? Question mark 0 or 1 time (that is optional)
# Hash mark 1 or more times, but each occurrence separated by a comma (',')