MDN wants to learn about developers like you: Redirect 1


Gets or sets the element's identifier (attribute id).


var idStr =; // Get the id. = idStr; // Set the id

where idStr is the ID of the element.


The ID must be unique in a document, and is often used to retrieve the element using getElementById.

In some documents (in particular, HTML, XUL, and SVG), the id of an element can be specified as an attribute on the element like so: <div id="main-content">.

However you can't use this attribute in a custom XML document without correctly specifying the type of the id attribute in the DOCTYPE.

Other common usages of id include using the element's ID as a selector when styling the document with CSS.

Note that IDs are case-sensitive, but you should not create IDs that differ only in the capitalization (see Case Sensitivity in class and id Names).


Specification Status Comment
Document Object Model (DOM) Level 2 HTML Specification Recommendation  


Document Tags and Contributors

 Last updated by: Sheppy,