Web/HTML/Global attributes/id

From Get docs


The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).


The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

This attribute's value is an opaque string: this means that web authors should not rely on it to convey human-readable information (although having your IDs somewhat human-readable can be useful for code comprehension, e.g. consider ticket-18659 versus r45tgfe-freds&$@).


id's value must not contain whitespace (spaces, tabs etc.). Browsers treat non-conforming IDs that contain whitespace as if the whitespace is part of the ID. In contrast to the class attribute, which allows space-separated values, elements can only have one single ID value.

Note: Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in [[../../../../Glossary/HTML5|HTML5]], an ID should start with a letter for compatibility.


Specifications

Specification Status Comment
HTML Living StandardThe definition of 'id' in that specification. Living Standard No change from latest snapshot, HTML 5.1
HTML 5.1The definition of 'id' in that specification. Recommendation Snapshot of HTML Living Standard, no change from HTML5
HTML5The definition of 'id' in that specification. Recommendation Snapshot of HTML Living Standard, now accept '_', '-' and '.' if not at the beginning of the id. It is also a true global attribute.
HTML 4.01 SpecificationThe definition of 'id' in that specification. Recommendation Supported on all elements but <base>, <head>, <html>, <meta>, <script>, <style>, and <title>.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
id Chrome

Full support Yes

Edge

Full support 12

Firefox Full support 32


Full support 32


No support ? — 32

Notes'

Notes' id is a true global attribute only since Firefox 32.

IE

Full support Yes

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android Full support 32


Full support 32


No support ? — 32

Notes'

Notes' id is a true global attribute only since Firefox 32.

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also

id by Mozilla Contributors is licensed under CC-BY-SA 2.5.