HTML ID
The id attribute is used to uniquely identify one element on a page.
ID Attribute Example
<h1 id="main-title">Welcome</h1>
ID vs Class
| Feature | ID | Class |
|---|---|---|
| Unique | Yes | No |
| Reusable | No | Yes |
| Used for | Single element | Group of elements |
ID with Attributes
<div id="header" title="Site header">
Header content
</div>
Important Notes
- IDs must be unique
- Used for anchors and scripting
- Do not repeat IDs