The id Attribute: Difference Between Class and ID

Difference Between Class and ID

<!-- A unique element -->
<h1 id="myHeader">My Cities</h1>

<!-- Multiple similar elements -->
<h2 class="city">London</h2>
<p>London is the capital of England.</p>

<h2 class="city">Paris</h2>
<p>Paris is the capital of France.</p>

<h2 class="city">Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>

An HTML element can only have one unique id that belongs to that single element, while a class name can be used by multiple elements.

Related concepts

The id Attribute: Difference Between Class and ID — Structure map

Clickable & Draggable!

The id Attribute: Difference Between Class and ID — Related pages: