The class attribute
An HTML attribute that assigns CSS class names to an element. The same class can be reused on many elements for shared styling.
What it does: Both paragraphs share class="lead". CSS targeting .lead { } will style both paragraphs identically. class="btn primary" applies two classes. CSS can target .btn or .primary independently or together. Unlike id, class values can be reused across many elements - that is the whole point of class-based styling. Class values must be wrapped in double quotes. class=btn without quotes is invalid HTML. Multiple classes are space-separated in one class attribute. Repeating the class attribute is invalid. Like all attributes, class goes in the opening tag only. Closing tags must not contain attributes. A dot (.) targets a class in CSS. A hash (#) targets an id. So .intro { } styles all elements with class="intro".
Common mistakes: Attribute names must be lowercase in HTML. CLASS should be written as class. Class values must be enclosed in double quotes: class="intro", not class=intro without quotes.
Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
classFill in the Blanks
Spot the Error
Create a free class, add this module to a journey, and track who's stuck.
Create a free teacher account →No credit card. No setup fee. Make a class and invite students in under three minutes.
Practice this topic interactively, track progress, and unlock badges.
Start Learning Free →