Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 495131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:33:51+00:00 2026-05-13T05:33:51+00:00

In CSS we can use both ID and class. is there any pros and

  • 0

In CSS we can use both ID and class. is there any pros and cons if i use Class always instead ID in terms of Semantic, Web standards- W3C , SEO , Accessibility and future maintainability?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:33:51+00:00Added an answer on May 13, 2026 at 5:33 am

    One big difference: in CSS, a class has a lower importance level than an ID.

    Imagine that each specification in a CSS declaration added a certain number of points to that declaration’s value. Let’s say the points go something like this (totally made up, but whatever):

    • Tag name (‘a’, ‘div’, ‘span’): 1 point
    • Class name (‘.highlight’, ‘.error’, ‘.animal’): 10 points
    • ID (‘#main-headline’, ‘#nav’, ‘#content’): 100 points

    So, the following declarations:

    a {
        color: #00f;
    }
    
    .highlight a {
        color: #0f0;
    }
    
    #nav .highlight a {
        color: #f00;
    }
    

    are worth 1, 11, and 111 points (respectively). For a given tag, the declaration with the highest number of points that matches it “wins”. So for example, with those declarations, all a tags will be blue, unless they’re inside an element with the “highlight” class, in which case they’ll be green, unless that element is inside the element with id=”nav”, in which case they’ll be red.

    Now, you can get yourself into tricky situations if you’re only using classes. Let’s say you want to make all the links in your content area blue, but all the links in your foo area red:

    .content a {
        color: #00f;
    }
    
    .foo a {
        color: #f00;
    }
    

    By my previous (made up) scale, those both have 11 points. If you have a foo within your content, which one wins? In this situation, foo wins because it comes after. Now, maybe that’s what you want, but that’s just lucky. If you change your mind later, and want content to win, you have to change their order, and depending on the order of declarations in a CSS file is A Bad Idea. Now if, instead, you had the following declaration:

    #content a {
        color: #00f;
    }
    
    .foo a {
        color: #f00;
    }
    

    Content would always win, because that declaration has a value of 101 (beating foo’s 11). No matter what order they come in, the content declaration will always beat the foo one. This provides you with some very important consistency. The winners won’t arbitrarily change based on changing orders in the file, and if you want to change the the winner, you have to change the declarations (maybe add a #content in front of the .foo declaration, so it will have 111 points).

    So basically, the differences in values are important, and you get a lot of inconsistency and seemingly arbitrary winners if you just use classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a collection of div elements, I can use CSS to have
Well, question is in title. Is it possible at all? I can use css
You can use the URL helper in Code Igniter to load CSS and Javascript
I can use FireFox and FireBug, in a pane, I can open a .css
What is a library I can use for CSS webkit support across multiple browsers
I have defined CSS in MasterPage so that all pages can use the same
Can we use whole page design jpg file as css-sprite without slicing?
Where do I find a good CSS editor that can help me use all
Please see the jQuery below: I am really wondering how can I use CSS
How can I link .scss files to be automatically use css color scheme?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.