CSS · Lesson 2 · 10 min
Classes & IDs
Target specific elements with .class and #id.
You will learn
- Style with .classname
- Style one element with #id
- Combine selectors
A class can be reused: <p class="highlight">. An id should be unique: <div id="hero">. In CSS, .highlight and #hero select them.
Edit CSS — live preview below
HTML context (read-only)
<h1>Class vs ID</h1> <p class="highlight">I use a class</p> <p class="highlight">Classes repeat</p> <p id="special">I use an id</p>
CSS
Live preview
Tip: Give .highlight a border with border: 2px solid #f59e0b.