What is specificity in CSS?
Overview
Specificity is used when styling is implemented to the same element by two or more selectors. This decides the styling to be implemented. In specificity, we use points for each styling. The styling implementation with more points wins the styling. Let's look at the illustration to understand how points are counted in CSS:
CSS points distribution
Attributes | Priority Point |
Element | 1 |
Classes | 10 |
ID | 100 |
Inline styling | 1000 |
As we can see in the table above, an element has the least priority point, which is 1. Inline styling has the most priority points, which is 1000.
Therefore, if we use styling on both attributes, the inline styling will be displayed.
Code
Explanation
In the CSS (SCSS) tab:
- Lines 1 and 2: We use red for the
<body>tag, which is an element. We also make bothNameandDate of birthred.
In the HTML file:
- Lines 4 and 8: We assign a blue color by making inline styling that works within the
formtag. This is because it has more priority points than thebodytag. This can be seen in the output.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved