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

FeatureIDClass
UniqueYesNo
ReusableNoYes
Used forSingle elementGroup 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