Skip to main content
D
HTML
HTML Classes

HTML Classes

HTML classes assign reusable identifiers to elements.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

HTML uses the `class` attribute to group elements. Multiple elements can share the exact same class name. CSS and JavaScript target these classes to apply styles or behavior.

Syntax

Syntax
1<!-- class syntax -->
2<p class="intro highlight">Text</p>

Example

Example
1<!-- this applies classes -->
2<!DOCTYPE html>
3<html lang="en">
4  <head>
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <title>Classes</title>
8  </head>
9  <body>
10    <p class="error">Something went wrong.</p>
11  </body>
12</html>

Try it Yourself

Hands-on Practice
Modify the code below to see how it affects the output. This is the best way to learn!
Interactive Editor
1234567891011121314151617181920
Live Preview

Key Points

  • The `class` attribute groups elements.
  • Multiple elements share the same class.
  • One element accepts multiple classes.
  • CSS targets classes to style pages.

Up Next

Continue your journey with the next topic.

Go to HTML Id