</> Code Corner

HTML · HTML Tutorial · Lesson 22

HTML Classes

Style many elements with the class attribute.

The class attribute specifies a class for an element. Multiple elements can share the same class.

Example

<style>
.city { background-color: tomato; color: white; padding: 10px; }
</style>

<div class="city"><h2>London</h2><p>Capital of England.</p></div>
<div class="city"><h2>Paris</h2><p>Capital of France.</p></div>

In CSS, select a class with a period (.) followed by the class name.

Multiple Classes

Keep reading “HTML Classes”

Sign up to read the full lesson (2 more parts), try every example in the live editor, and take the 5-question quiz.

Chat with us 👋