class
One or more classes of an element — the main way to reach it from CSS.
Syntax
<p class="name another">…</p>Examples
One class on several elements and several classes on one:
<style>
.tag { padding: 2px 8px; border-radius: 10px; background: #eee; }
.hot { background: tomato; color: white; }
</style>
<span class="tag">Coffee</span>
<span class="tag">Tea</span>
<span class="tag hot">Sale</span>Notes
Classes are separated by spaces; in CSS they are reached with a dot: .tag. Unlike id, one class can be used on any number of elements. Name classes by meaning (card, price), not by look (red, big).
See also
In the tutorial
- Attributes — How HTML attributes work, the global attributes id, class, title, lang, hidden and style, boolean attributes and data attributes.