Javatpoint Logo
Javatpoint Logo

HTML Id Attribute

The id attribute refers to a unique value for an HTML element. This HTML id value can be used with CSS and JavaScript to perform certain task.

HTML id with CSS

In CSS, if you want to select an element with a specific id, write a hash (#) character, followed by the id of the element.


Use the HTML id "myid" with CSS:

Note: Here the id attribute is "myid" which can be used on any HTML element. The HTML id value is case-sensitive and it must contain at least one character, and must not contain whitespace (spaces, tabs, etc.).

Difference between HTML Class and ID

An HTML class name can be used by multiple elements while An HTML element can only have one unique id that belongs to that single element.


Test it Now

HTML id with JavaScript

You can use HTML id with JavaScript getElementById() method to access an element with a specified id.


Test it Now
Next TopicHTML Iframes

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA