Lesson 17: HTML Classes

Targeting Elements with Classes

The class attribute specifies one or more class names for an element. Classes allow CSS styles or JavaScript scripts to target multiple elements at once.

<p class="intro">Introductory text.</p>

Why&How to use:

Assign reusable class names to apply uniform styling or behaviors across multiple elements throughout your entire website.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Classes</title>
<style>
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<p class="highlight">First highlighted paragraph.</p>
<p>Normal paragraph without class.</p>
<p class="highlight">Second highlighted paragraph.</p>
</body>
</html>