L' attributo globale id definisce un identificatore univoco(ID) che deve esser univoco nell'intero documento. Il suo scopo è quello di identificare l'elemento in un collegamento(using a fragment identifier), negli script, o nella parte grafica (con i CSS).
Il valore di questo attributo è una "stringa opaca": questo significa che l'autore non lo utilizza per comunicare informazioni. Particular meaning, for example semantic meaning, must not be derived from the string.
Il valore di questo attributo non deve contenere whitespace (spazi, tab etc.). I browser trattano i whitespace che sono nell'ID come se ne facessero parte. Al contrario dell'attributo class, che permette valori separati da uno spazio, ogni elemento puo avere soltanto un ID.
Nota: Usando caratteri al di fuori delle lettere, numeri, '_'
, '-'
e '.'
, può causare problemi di compatibilità, dato che loro non sono permessi nell'HTML 4. Anche questa restrizione è stata rimossa nell'HTML 5, un id dovrebbe iniziare con una lettera per compatibilità.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'id' in that specification. |
Living Standard | No change from latest snapshot, HTML 5.1 |
HTML 5.1 The definition of 'id' in that specification. |
Recommendation | Snapshot of HTML Living Standard, no change from HTML5 |
HTML5 The definition of 'id' in that specification. |
Recommendation | Snapshot of HTML Living Standard, now accept '_' , '-' and '.' if not at the beginning fo the id. It is also a true global attribute. |
HTML 4.01 Specification The definition of 'id' in that specification. |
Recommendation | Supported on all elements but <base> , <head> , <html> , <meta> , <script> , <style> , and <title> . |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes)[1] | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes)[1] | (Yes) | (Yes) | (Yes) |
[1] id
is a true global attribute only since Gecko 32.0 (Firefox 32.0 / Thunderbird 32.0 / SeaMonkey 2.29).
See also
- All global attributes.
Element.id
that reflects this attribute.