HTML id attribute
- closing tag
- n/a — attribute
- void element
- n/a
- lives inside
- any opening tag
- typically holds
- exactly one name
Where it goes
Same place as class: inside the tag's opening brackets, like <h1 id="main-title">.
Example
<h1 id="main-heading">Welcome</h1>Open this example in the editor →
Common mistakes
- Using the same id on two tags. That breaks anything (CSS, JavaScript, links) that expects it to be unique.
- Writing the attribute in the closing tag, like </h1 id="main-title">. Closing tags never carry attributes. It is just </h1>.