I know its quite easy topic, but I found the syntax provided on w3.com is quite complex. Can anyone decode it? Is it important to understand it?
media_query_list
: S* [media_query [ ',' S* media_query ]* ]?
;
media_query
: [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
| expression [ AND S* expression ]*
;
media_type
: IDENT
;
expression
: '(' S* media_feature S* [ ':' S* expr ]? ')' S*
;
media_feature
: IDENT
;
It also specifies some tokens below it. Can anyone please decode them also.
This is a formal EBNF definition of the syntax. If you’re looking for easy-to-read examples, have a look at chapter 2 of the standard.
In short,
Sstands for a space character,IDENTfor an identifier (likefoobar2),*for zero or more repetitions. Let’s go through it in detail:means that a
media_query_list(that’s the everything that can be in@media ( here )) consists of one or moremedia_query, separated by comma and optional spacing. For example, these are validmedia_query_lists:The definition of
media_queryis given later, inThe
|means there are two forms. Either one of(and optional expressions, joined with
AND), or just an expression followed by optional multiple other expressions, joined withAND.An expression is defined as follows:
That means it’s always in parentheses, and consists of either just a
media_feature, or a media feature followed by anexpr. For example, these are valid expressions:In this definition,
media_typeandmedia_featurecan be arbitrary identifiers. In practice, they will be identifiers that are recognized by the browsers, likeprint,screen,max-widthetc..