Cascading & Specificity

What is cascade in css?

The CSS cascade is an algorithm who’s job is to select CSS declarations in order to determine the correct values for CSS properties

h2{

     background-color: pink;

}

h2{

    background-color:red; (Final Color)

}

CSS Cascade algorithm check:

1) selectors are are same in our example h2

2) if we apply any property to the final selector, then it will be applied for that selector. 

in our example, the h2 selector having background-color property as  pink, then we redeclare it and change its background color property to red, so finally h2 selector having color red

If Selectors are different then we check specificity.

What is specificity?

Specificity is an algorithm that calculates the weight that is applied to a given CSS declaration. It is an 3 digit number

Element Selector
class,pesudo-calss
Remember Aboves
Inline styles having more specificity
Question

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top