HTML ID Attribute

The id attribute provides a unique identifier for an HTML element. IDs must be unique within a page.

Using IDs

The id attribute assigns a unique identifier to an element. No two elements should have the same id on the same page.

IDs are used for CSS styling, JavaScript manipulation, and anchor links for page navigation.

<!-- Unique IDs -->
<header id="main-header">Header</header>
<nav id="main-nav">Navigation</nav>
<main id="content">Content</main>

<!-- Anchor link to ID -->
<a href="#content">Jump to Content</a>