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 7580501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:56:00+00:00 2026-05-30T17:56:00+00:00

Possible Duplicate: Points in CSS specificity Here’s an example of what I mean: http://jsfiddle.net/BTJXt/9/

  • 0

Possible Duplicate:
Points in CSS specificity

Here’s an example of what I mean:

http://jsfiddle.net/BTJXt/9/

Somehow 1 ID will beat a seemingly infinite number of classes. How is this being calculated?

<style>
    div {
    height:200px;
    width:200px;
    }

    #big .little {
    /* Specificy value = 110 */
    background-color:red;
    }

     #big .little.little {
    /* Specificy value = 120 */
    background-color:blue;
    }

    .little.little.little.little.little.little.little.little.little.little.little.little.little {
    /* Specificy value = 130, why doesn't this win? */
    background-color:green;
    }


</style>   

<div id="big">
    <div class="little"></div>
</div>​
  • 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-30T17:56:02+00:00Added an answer on May 30, 2026 at 5:56 pm

    Simply put: an ID will always beat any number of classes, pseudo-classes, attribute selectors or type selectors, but not necessarily another ID. That’s all you need to remember.

    Or to get into the technical nitty gritty: specificity isn’t counted in some decimal numeric base that we all use. IDs are not worth “100 points”, classes/attributes/pseudo-classes are not “10 points”, types/pseudo-elements are not “1 point”, etc. You don’t add these numbers up and compare them, mathematically, based on their sum; that’s not how it works. (You do add up the individual number of IDs, number of classes/attributes/pseudo-classes, etc, but you don’t add all the individual numbers up to a single total.)

    The specificity of these simple selectors is counted in a rather different way. The spec says it best:

    9. Calculating a selector’s specificity

    A selector’s specificity is calculated as follows:

    • count the number of ID selectors in the selector (= a)
    • count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
    • count the number of type selectors and pseudo-elements in the selector (= c)
    • ignore the universal selector

    Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.

    Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.

    Examples:

    *               /* a=0 b=0 c=0 -> specificity =   0 */
    LI              /* a=0 b=0 c=1 -> specificity =   1 */
    UL LI           /* a=0 b=0 c=2 -> specificity =   2 */
    UL OL+LI        /* a=0 b=0 c=3 -> specificity =   3 */
    H1 + *[REL=up]  /* a=0 b=1 c=1 -> specificity =  11 */
    UL OL LI.red    /* a=0 b=1 c=3 -> specificity =  13 */
    LI.red.level    /* a=0 b=2 c=1 -> specificity =  21 */
    #x34y           /* a=1 b=0 c=0 -> specificity = 100 */
    #s12:not(FOO)   /* a=1 b=0 c=1 -> specificity = 101 */
    

    Notice that it says “concatenating” (as in joining strings together), not “adding” (as in the arithmetic sense of 2 + 2 = 4).

    Notice also that it says “a number system with a large base”; this is just to illustrate that you don’t take these specificity scores as decimal numbers, where 13 × 10 = 130 is greater than 1 × 100 = 100 in layman’s terms.

    This is how you would calculate the specificity of your selectors:

    /* 1 ID, 1 class     -> specificity = 1-1-0 */
    #big .little
    
    /* 1 ID, 2 classes   -> specificity = 1-2-0 */
    #big .little.little
    
    /* 0 IDs, 13 classes -> specificity = 0-13-0 */
    .little.little.little.little.little.little.little.little.little.little.little.little.little
    

    Notice now how the specificity of the third selector is less than the first two, because there are no ID selectors in use?

    When comparing the other two selectors, both of which have an ID selector each, you’ll see that the second selector has one more class. In this case, the second selector wins due to the extra class selector, even though each has an ID selector, because the ID selectors by themselves share equal specificity.

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

Sidebar

Related Questions

Possible Duplicate: Cross-browser CSS Ok, so the question might be somehow a little confusing.
Possible Duplicate: Why do browsers create vendor prefixes for CSS properties? For example, if
Possible Duplicate: post and pre increment in c Undefined Behavior and Sequence Points here
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Undefined Behavior and Sequence Points after the following c++ code, the array
Possible Duplicate: Radius of multiple latitude/longitude points distance calculations in mysql queries select within
Possible Duplicate: Undefined Behavior and Sequence Points int a=10; a=a++; a=++a; a=(a++); Can you
Possible Duplicate: What's the point of valid CSS/HTML? This is a over-asked question, but
Possible Duplicate: CSS Drop Down Menu I am trying to create a drop down

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.