# Grammar ## Limitations/Restrictions ### Colors We support the 16 built-in level 1 CSS color keywords, in addition to the following: - RGB - HSL - HEX We do not support the CSS `color` function ### Pseudo Elements We do not support using Pseudo Elements (example: `::before`) ### Browser Prefixing We do not support using browser prefixes (example: `-webkit-appearance`) ### Grid and Flex we are not supporting grid or flex related properties ### Whitespace This document intentionally ignores whitespace. ### Case sensitivity Although CSS is often case insensitive. This document is intentionally case sensitive. ### Operator Persistence and ambiguity This document intentionally ignores operator persistence. This mean that this document describes an ambiguous grammar ### Shorthands we are not supporting multi type shorthand properties like `font` and `border` but we are supporting shorthands for multiple sides like `border-color` and `margin` ### Things we might add later these are features we don't currently have included but might include in the future. - value functions `calc(max(100vh, 100%) - 64px)` - more properties - key frames - font face declarations ## Tokens ```bnf ::= "0" - "9" ::= "a" - "z" | "A" - "Z" | "_" | "-" ::= | ::= | ::= ::= "(" ::= "@" ::= "#" ::= """ """ | "'" "'" ::= "url(" ")" ::= | ::= | "." | "+" | "+" "." | "-" | "-" "." ::= "%" ::= ::= " " | "\t" | "\n" | "\r" ::= | ``` ## Stylesheet ```bnf ::= ::= | | "" ``` ## Imports ```bnf ::= | "" ::= "@import" ";" | "@import" ";" ``` ## Media Query ```bnf ::= "@media" "{" "}" ::= "," | ::= | "(" ")" | "not" | "and" | "or" | "(" ")" ::= "all" | "screen" | "print" ::= "color" | "monochrome" ::= "width:" | "min-width:" | "max-width:" | "height:" | "min-height:" | "max-height:" ::= "orientation:" ::= "hover:" | "any-hover:" | "pointer:" | "any-pointer:" ::= "prefers-color-scheme:" ::= "portrait" | "landscape" ::= "hover" | "none" ::= "fine" | "coarse" | "none" ::= "dark" | "light" ``` ### Examples ```css @media print {} @media (color) {} @media (max-width: 1250px) {} @media (pointer: fine), (pointer: coarse) {} @media screen and (min-width: 30em) and (orientation: landscape) {} @media not print and (monochrome) {} @media (not (color)) or (hover) {} ``` ## Rules ```bnf ::= "{" "}" ``` ## Selectors ```bnf ::= "," | ::= | ::= | "+" | ">" | "~" ::= | | ::= "*" | ::= | ::= | ::= "." | "#" | ::= "[" "]" | "[" "=" "]" | "[" "~=" "]" | "[" "|=" "]" | "[" "^=" "]" | "[" "$=" "]" | "[" "*=" "]" ::= ":focus" | ":focus-within" | ":focus-visible" | ":hover" | ":visited" | ":default" | ":active" | ":target" | ":root" | ":checked" ::= ":not(" ")" | ":has(" ")" ``` ### Examples ```css * {} p {} #id {} .class {} [title="title"] {} :focus {} .class p {} :not(a.class#id > :hover:not(a.class)) p {} p.class.class2#id[target].class:has(p.class) {} ``` ## Declarations ```bnf ::= ";" | | ";" ::= ":" | ":" ::= ":" | ":" ::= "font-family" ":" | | ::= "opacity" ":" ::= "text-align" ":" ::= "display" ":" ::= "position" ":" ::= "color" | "background-color" ::= "border-color" ::= "font-size" | "min-height" | "height" | "max-height" | "min-width" | "width" | "max-width" | "top" | "bottom" | "left" | "right" ::= "margin" | "padding" | "border-width" | "border-radius" ::= | ::= "block" | "inline" | "inline-block" ::= "static" | "relative" | "absolute" | "fixed" | "sticky" ``` ### Examples ```css * { text-align: center; color: red; background-color: blue; height: 100px; width: 100px; font-size: 18px; font-family: Arial; font-family: "Arial"; opacity: 0.5; padding: 10px; } ``` ## Values ```bnf ::= | | ::= | ::= "%" ::= "0" | ::= "px" | "cm" | "in" | "pt" | "em" | "rem" | "vh" | "vw" | "vb" | "vi" | "vmin" | "vmax" | "ch" ::= | | ::= "black" | "silver" | "gray" | "grey" | "white" | "maroon" | "red" | "purple" | "fuchsia" | "green" | "lime" | "olive" | "yellow" | "navy" | "blue" | "teal" | "aqua" | | | ::= "rgb(" <0-255> "," <0-255> "," <0-255> ")" | "rgba(" <0-255> "," <0-255> "," <0-255> "," ")" ::= "#" | "#" | "#" | "#" ::= | "a" - "f" | "A" - "F" ::= ::= "hsl(" <0-360> "," <0-100> "%," <0-100> "%)" | "hsla(" <0-360> "," <0-100> "%," <0-100> "%," ")" ::= "0." | "." | 1 | 0 ::= "left" | "right" | "center" | "justify" ```