Classes are reusable labels for CSS and JavaScript. One element may have several classes, and each class is separated by spaces in the class attribute.
What You Need to Know
Reordering class names in HTML does not itself set CSS priority. CSS specificity and stylesheet order decide which conflicting declarations win.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<div class="card highlighted student-card">
<h2>New student</h2>
<p>All three classes apply to this element.</p>
</div>
Let’s Understand the Example
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- An h2 starts a major section beneath the page topic.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
- Class is a reusable label for styling or scripts; several elements may share the same class.
You should see a readable heading and its related content. The heading level tells readers how the ideas fit together, not merely how large the letters look.
What Should You See?
The page should display “New student” as a heading, followed by its related content. Change the heading text and refresh the browser to see the result.
Read only the headings, from top to bottom. Do they tell a sensible story? If not, move sections or choose levels that match the content.
Try It Yourself
- Give the card a new class called special, then style that class in CSS later.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Thinking that putting the last class name at the end always makes its CSS rules win.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- Classes are reusable labels for CSS and JavaScript.
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- Reordering class names in HTML does not itself set CSS priority. CSS specificity and stylesheet order decide which conflicting declarations win.