HTML idAttributes
Examples
Use the id attribute to manipulate a paragraph using JavaScript:
Try it Yourself »
More examples are included at the bottom of this chapter.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the id attribute
Definition and Usage
The id attribute specifies a unique id for an HTML element.
The id must be unique in the HTML document.
The id attribute can be used as a link anchor, and to change or add styles to the element with a specified id via JavaScript (HTML DOM) or via CSS.
Differences Between HTML 4.01 and HTML5
In HTML5, the id attribute can be used on any HTML element (it will validate on any HTML element, but may not necessarily be useful).
In HTML 4.01, the id attribute cannot be used on: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.
Note:HTML 4.01 has strict restrictions on the value of id (for example, in HTML 4.01, id values cannot start with a number).
Syntax
Attribute Values
| Value | Description |
|---|---|
| id |
Specifies the unique id of the element. Naming rules:
|
|
|
More Examples |
Using the id attribute in CSS
How to use the id attribute in CSS to add styles to elements
HTML Global Attributes Other Extensions