The id Attribute
An id must be unique in the page. Use it for bookmarks, for linking a label to an input, and to find one element from JavaScript. In CSS an id selector starts with #.
For styling, classes are usually a better choice because they can be reused.
Example
<style>#hero { background: #166534; color: white; padding: 16px; }</style>
<div id="hero">I am the only element with this id.</div>Exercise
Which selector targets id "hero"?
hero { color: red; }Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.