Javatpoint Logo
Javatpoint Logo

HTML Id Attribute

The id attribute is used to specify the unique ID for an element of the HTML document. It allocates the unique identifier which is used by the CSS and the JavaScript for performing certain tasks.

Note: In the Cascading Style sheet (CSS), we can easily select an element with the specific id by using the # symbol followed by id.

Note: JavaScript can access an element with the given ID by using the getElementById() method.

Syntax

Example 1: The following example describes how to use the id attribute in CSS document:

Test it Now

Output:

HTML Id Attribute

Example 2: The following example describes how to use the ID attribute in JavaScript.

Test it Now

Output:

HTML Id Attribute

Browser Support

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<id>YesYesYesYesYes

Next TopicHTML List Box





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA