Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

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

  • id — A unique identifier of an element on the page.
  • style — CSS properties right on the element (inline styles).
  • <div> — A block container without meaning: groups elements for styling and layout.

In the tutorial

  • Attributes — How HTML attributes work, the global attributes id, class, title, lang, hidden and style, boolean attributes and data attributes.

Thanks for reading!

Donate to the site — we work hard for you.