Skip to the page
css reference · selectors

CSS .class selector

type
selector
applies to
every element carrying that class
inherits
n/a
common values
.card, .btn, .active

Where it goes

Anywhere the same look is needed on several tags that are not related in any other way.

Example

.card {
  border: 1px solid #ccc;
  padding: 16px;
}

Common mistakes

  • Naming classes after how something looks (.red-text) instead of what it is (.error). The look will change. The name should not have to.
  • Doubling up classes in the selector (.card.card) to force a rule to win, instead of checking why the first rule lost.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.