CrazyEngineers
  • Difference between Class & ID in CSS?

    Whats In Name

    Whats In Name

    @whats-in-name-KdgM7o
    Updated: Oct 21, 2024
    Views: 1.3K
    What's the difference between class and id in CSS , I can only find out that class is for particular group of elements and id is for unique element, but please explain me with example and how can't we use one element over other?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberJan 21, 2013

    Id is used to select a single element and apply properties.
    #divId
    {
    text-align:center;
    }
    
    Element <div id="divId" ></Div> will get above property.

    while class used to apply on group of element wherever that property found.
    .center {text-align:center; color:red} 
    For any element you add class="center" will get above property.

    #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • Whats In Name

    MemberJan 21, 2013

    ianoop
    Id is used to select a single element and apply properties.
    #divId
    {
    text-align:center;
    }
    
    Element <div id="divId" ></Div> will get above property.
    Does this mean that now,we cannot use id="divid" for any other element?
    Are you sure? This action cannot be undone.
    Cancel
  • Anoop Kumar

    MemberJan 21, 2013

    you can give same ID to different elements but while identifying by ID , 1st occurrence will considered and others will be discarded, since HTML parsed as DOM tree model.
    Best Html practice is to always give ID property and identify by ID rather than name.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register