From 854d01fdc4528bea755ef628c5cdd0c9c8acd859 Mon Sep 17 00:00:00 2001 From: wbamberg Date: Fri, 21 Jun 2024 20:26:15 -0700 Subject: [PATCH] Correct syntax rules for --- files/en-us/web/css/ident/index.md | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/files/en-us/web/css/ident/index.md b/files/en-us/web/css/ident/index.md index f7101f51bc66290..9a2af06ad1cf3a4 100644 --- a/files/en-us/web/css/ident/index.md +++ b/files/en-us/web/css/ident/index.md @@ -11,17 +11,30 @@ The **``** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS ## Syntax -The syntax of `` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It consists of one or more characters, where characters can be any of the following: +A CSS identifier consists of one or more characters, where characters can be any of the following: -- any alphabetical character (`A` to `Z`, or `a` to `z`), -- any decimal digit (`0` to `9`), -- a hyphen (`-`), -- an underscore (`_`), -- an escaped character (preceded by a backslash, `\`), -- a [Unicode](https://en.wikipedia.org/wiki/Unicode) character (in the format of a backslash, `\`, followed by one to six hexadecimal digits, representing its Unicode code point) +- any ASCII character `A-Z` and `a-z` +- any decimal digit (`0` to `9`) +- a hyphen (`-`) +- an underscore (`_`) +- any other Unicode character `U+00A0` and higher (that is, any other non-ASCII Unicode character) +- an [escaped character](escaping_characters). + +Additionally, an identifier must not start with an unescaped digit, and must not start with an unescaped hyphen followed by an unescaped digit. Note that `id1`, `Id1`, `iD1` and `ID1` are all different identifiers as they are [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). On the other hand, as there are several ways to escape a character, `toto\?` and `toto\3F` are the same identifiers. +### Escaping characters + +Any character except a hexadecimal digit (`[0-9a-fA-F]`) can be escaped by placing a backslash in front of it. For example, `&` can be escaped as `\&`. + +Any character can be escaped with a backslash followed by followed by one to six hexadecimal digits, representing the character's Unicode {{glossary("code point")}}. For example, `&` can be escaped as `\26`. In this situation, if the character following the escaped character is a hexadecimal digit, then either: + +- a space or other whitespace character must be placed after the Unicode code point, or: +- the Unicode code point must be given in full, with all six digits. + +For example, the string `&123` could be escaped as `\26 123` or `\000026123`. + ## Examples ### Valid identifiers @@ -32,8 +45,10 @@ ground-level A mix of alphanumeric characters and a dash -test A dash followed by alphanumeric characters --toto A custom-property like identifier _internal An underscore followed by alphanumeric characters -\22 toto A Unicode character followed by a sequence of alphanumeric characters +\22 toto An escaped character followed by a sequence of alphanumeric characters +\000022toto The same as the previous example bili\.bob A correctly escaped period +🔥123 A non-ASCII character followed by numbers ``` ### Invalid identifiers @@ -41,7 +56,7 @@ bili\.bob A correctly escaped period ```plain example-bad 34rem It must not start with a decimal digit. -12rad It must not start with a dash followed by a decimal digit. -bili.bob Only alphanumeric characters, _, and - needn't be escaped. +bili.bob ASCII characters apart from alphanumerics must be escaped. 'bilibob' This would be a {{CSSxRef("<string>")}}. "bilibob" This would be a {{CSSxRef("<string>")}}. ```