Wael Assaf Wael Assaf - 2 years ago 55
HTML Question

The difference between ids an classes in HTML

I am learning HTML and CSS from a book and I've faced a problem with connecting between the ids and classes, can any one answer me when to use them?

<p id=”footer”>Please steal this page, it isn’t copyrighted in any way</p>
<p class="guarantee">

The book said : Giving an element an id is similar to adding an element to a class. The only differences are that the attribute is called “id”, not “class”, an element can’t have multiple ids, and you can’t have more than one element on a page with the same id.
but still not understand when to use them :P
thanks guys

Answer Source

classes are generally used to group elements together while ids are used to identify specific elements.

<div class="buttonContainer">
    <button id="home">home</button>
    <button id="about">about</button>
    <button id="contact">contact</button>

<div class="buttonContainer">
    <button id="email">email</button>
    <button id="query">query</button>

another example

<div id="header">
    <p class="title">Header Title Here</p>

<div id="footer">
    <p class="title">Footer Title Here</p>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download