Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

HTML id Attribute

Definition and Usage

The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.

Applies to

The id attribute is a Global Attribute, and can be used on any HTML element.

Element Attribute
All HTML elements id



Use the id attribute to manipulate text with JavaScript:


<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>

function displayResult() {
    document.getElementById("myHeader").innerHTML = "Have a nice day!";

Try it Yourself »

Browser Support

id Yes Yes Yes Yes Yes