Feuille de style CSS – Modules

La règle-at @charset

@charset "UTF-8";

 

4.1.5 Les règles-at

Les règles-at commencent par un mot-clé-at, composé du caractère « @ » immédiatement suivi par un identificateur (ex. ‘@import’, ‘@page’).

 

 

 

 

https://developer.mozilla.org/fr/docs/Web/CSS/@charset
La règle @  @charset définit l’encodage des caractères utilisés dans la feuille de style. Cette règle doit être le premier élément de la feuille de style (aucun caractère ne doit être écrit avant). Cette règle ne fait pas partie des instructions imbriquées et ne peut donc pas être utilisée à l’intérieur des groupes conditionnels. Si plusieurs règles @charset sont définies, seule la première sera utilisée. Cette règle ne pourra pas être utilisée au sein d’un attribut style d’un élément HTML ou avec l’élément <style> car c’est l’encodage du document HTML qui est alors pris en compte.

Cette règle @ s’avère notamment utile lorsqu’on utilise des caractères non-ASCII pour certaines propriétés CSS telles que content.

Le moteur dispose de différentes méthodes pour déterminer l’encodage d’une feuille de style. Il utilisera ces ces méthodes dans l’ordre qui suit et s’arrêtera dès qu’un résultat sera obtenu (autrement dit, les règles qui suivent sont triées par priorité décroissante) :

La valeur du caractère indiquant l’ordre des octets Unicode qui est placé au début du fichier (le BOM)
La valeur fournie par l’attribut charset de l’en-tête HTTP Content-Type ou l’information équivalente dans le protocole utilisé pour servir la feuille de style.
La règle @ CSS @charset.
L’encodage défini dans le document appelant la ressource (l’attribut charset de l’élément <link>). Cette méthode est désormais obsolète et ne doit plus être utilisée.
Dans tous les autres cas, on considère que le document est encodé en UTF-8

Syntaxe

@charset « UTF-8 »;

 

4.4 CSS style sheet representation

A CSS style sheet is a sequence of characters from the Universal Character Set (see [ISO10646]). For transmission and storage, these characters must be encoded by a character encoding that supports the set of characters available in US-ASCII (e.g., UTF-8, ISO 8859-x, SHIFT JIS, etc.). For a good introduction to character sets and character encodings, please consult the HTML 4 specification ([HTML4], chapter 5). See also the XML 1.0 specification ([XML10], sections 2.2 and 4.3.3, and Appendix F).

When a style sheet is embedded in another document, such as in the STYLE element or « style » attribute of HTML, the style sheet shares the character encoding of the whole document.

When a style sheet resides in a separate file, user agents must observe the following priorities when determining a style sheet’s character encoding (from highest priority to lowest):

An HTTP « charset » parameter in a « Content-Type » field (or similar parameters in other protocols)
BOM and/or @charset (see below)
<link charset= » »> or other metadata from the linking mechanism (if any)
charset of referring style sheet or document (if any)
Assume UTF-8

Authors using an @charset rule must place the rule at the very beginning of the style sheet, preceded by no characters. (If a byte order mark is appropriate for the encoding used, it may precede the @charset rule.)

After « @charset », authors specify the name of a character encoding (in quotes). For example:

@charset « ISO-8859-1 »;

@charset must be written literally, i.e., the 10 characters ‘@charset « ‘ (lowercase, no backslash escapes), followed by the encoding name, followed by ‘ »;’.

The name must be a charset name as described in the IANA registry. See [CHARSETS] for a complete list of charsets. Authors should use the charset names marked as « preferred MIME name » in the IANA registry.

User agents must support at least the UTF-8 encoding.

User agents must ignore any @charset rule not at the beginning of the style sheet. When user agents detect the character encoding using the BOM and/or the @charset rule, they should follow the following rules:

Except as specified in these rules, all @charset rules are ignored.
The encoding is detected based on the stream of bytes that begins the style sheet. The following table gives a set of possibilities for initial byte sequences (written in hexadecimal). The first row that matches the beginning of the style sheet gives the result of encoding detection based on the BOM and/or @charset rule. If no rows match, the encoding cannot be detected based on the BOM and/or @charset rule. The notation (…)* refers to repetition for which the best match is the one that repeats as few times as possible. The bytes marked « XX » are those used to determine the name of the encoding, by treating them, in the order given, as a sequence of ASCII characters. Bytes marked « YY » are similar, but need to be transcoded into ASCII as noted. User agents may ignore entries in the table if they do not support any encodings relevant to the entry.

If the encoding is detected based on one of the entries in the table above marked « as specified », the user agent ignores the style sheet if it does not parse an appropriate @charset rule at the beginning of the stream of characters resulting from decoding in the chosen @charset. This ensures that:
@charset rules should only function if they are in the encoding of the style sheet,
byte order marks are ignored only in encodings that support a byte order mark, and
encoding names cannot contain newlines.

User agents must ignore style sheets in unknown encodings.

Commentaires CSS et sommaire

 

Reset CSS

 

Polices embarqués