CSS: Differences between Class and ID

Posted on 2011-10-18
Last Modified: 2012-05-12
What are the differences in usability between defining the CSS is a Class versus an ID?

Question by:newbieweb
    LVL 82

    Accepted Solution

    'class' is intended to used for styling multiple elements on a page with the same style rules.  'id' is supposed to be unique on a page.  'id' is used by javascript to 'identify' specific elements.  If you duplicate an 'id' on a page, you can find that your javascript doesn't do what you though it would.

    Author Closing Comment

    Got it!
    LVL 51

    Expert Comment


    .classStyle {....}
    #idStyle {...}

    <div class=classStyle>...</div>
    <table class=classStyle>...</table>
    <p id=idStyle>...</p>

    we applied same class to 2 different element and applied a style to a special element by defining the id in style

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now