Free HTML tutorial

HTML IDs and Page Anchors

An id identifies one element on a page. Use unique id values to target an element or create a link directly to a section.

Assign a unique ID

<h2 id="contact">Contact</h2>

In CSS, target the element with a hash selector:

#contact {
  scroll-margin-top: 6rem;
}

Link to a section

<a href="#contact">Go to contact information</a>

IDs should be unique within a document. If you want to style many elements the same way, use a class instead.