Skip to the page
html reference · grouping

HTML class attribute

closing tag
n/a — attribute
void element
n/a
lives inside
any opening tag
typically holds
one or more names, space-separated

Where it goes

Inside the tag's own opening brackets, right after the tag name: <div class="card">. Never as loose text after the tag.

Example

<p class="highlight">Styled text</p>
<p class="highlight">Also styled, same way</p>

Open this example in the editor →

Common mistakes

  • Writing <div> class="card">. The attribute has to come before the closing >, not after it.
  • Leaving off the quotes: class=card. Browsers often forgive it. It is still not correct HTML.
  • Using class for something there is only one of. That is what id is for.

Related

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