freecoding.school100% FREE · NO SIGNUP
Markup CityISSUE #24 of 39

ids · unique handles

Tagg the BuilderVSThe Unclosed Tag
Tagg the Builder saysAn id is a unique name for a single element — for in-page links, label targets, and precise JS/CSS hooks.

An id must be unique on the page. Use it to jump to an element with #id in a link, to connect a <label for> to an input, or to grab one element in JavaScript with getElementById.

For styling, prefer classes — ids have very high CSS specificity, which makes their rules hard to override later. Think of an id as a name tag for exactly one thing.

Power-ups you unlock

The Unclosed Tag attacks — common mistakes

Boss battleGive a section an id and link to it from the top of the page. Then connect a <label for> to an <input id> and click the label to focus the input.

Example code

<!doctype html>
<html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff">
  <a href="#details">go to details</a>
  <div style="height:160px"></div>
  <h2 id="details" style="color:#b388ff">details</h2>
  <label for="nm">name</label>
  <input id="nm">
</body></html>
▶ Open the interactive comic issue
‹ Classes · Reusable HooksIframes · Pages Inside Pages ›