Includes only ID selectors, e.g. #example
. Each ID in a matching selector adds 1-0-0 to the weight value.
.foo
, attribute selectors, e.g. [type="radio"]
, and pseudo-classes, e.g. :hover
. Each class, attribute selector, or pseudo-class in a matching selector adds 0-1-0 to the weight value.p
, and pseudo-elements, e.g. ::before
, and all other selectors with double-colon notation. Each type or pseudo-element in a matching selector adds 0-0-1 to the weight value.*
, the pseudo-class :where()
, and its parameters have a value of 0-0-0. They match elements but do not impact the specificity weight value.+
, >
, ~
, " "
, ||
) do not add any value to the specificity weight.&
nesting combinator does not increase specificity weight, but nested rules do. Nesting, in terms of specificity and functionality, is similar to the :is()
pseudo-class.:is()
, :has()
, and negation :not()
pseudo-classes themselves do not add weight. The specificity weight is determined by the selector parameter in the list of selectors with the highest specificity.Sources and recommended, further resources on the topic:
License: CSS selectors cheat sheet by Jonas Jared Jacek is licensed under CC BY-NC-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. If others modify or adapt the material, they must license the modified material under identical terms. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/publications/css-selectors-cheat-sheet">CSS selectors cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-NC-SA 4.0</a>.</p>
For more information see the DITig legal page.