🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #109

CSS Specificity


CSS Specificity

CSS specificity is an algorithm that determines which style declaration is ultimately applied to an element.

If two or more CSS rules point to the same element, the declaration with the highest specificity will "win", and that style will be applied to the HTML element.

Look at the following examples:

Example

  <html>
<head>
  <style>
    p {color: red;}

  </style>
</head>
<body>

<p>Hello World!</p>

</body>

  </html>

Now, look at next example:

Example

  <html>
<head>
  <style>
    .test {color: green;}

    p {color: red;}
  </style>
</head>
<body>

<p class="test">Hello World!</p>

</body>
</html>

Now, look at next example:

Example

  <html>
<head>
  <style>
    #demo {color: blue;}

  .test {color: green;}
    p {color: red;}

  </style>
</head>
<body>

<p id="demo" class="test">Hello
  World!</p>

</body>
</html>

Now, look at next example:

Example

  <html>
<head>
  <style>
    #demo {color: blue;}

  .test {color: green;}
    p {color: red;}

  </style>
</head>
<body>

<p id="demo" class="test"
  style="color: pink;">Hello World!</p>

</body>
</html>

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

CSS Specificity – FAQs

Quick answers about learning CSS Specificity in CSS.

This free note from CodingNow 2.0 explains CSS Specificity in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including CSS Specificity, is 100% free with no signup required.
With focused practice, most students grasp CSS Specificity in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now