When more than one set of CSS rules apply to the same element, the browser will have to decide which specific set will be applied to the element. The rules the browser follows are collectively called Specificity
Specificity Rules include:
- Inline CSS>Internal CSS>External CSS
- CSS style applied by referencing external stylesheet has lowest precedence and is overridden by Internal and inline CSS.
- Internal CSS is overridden by inline CSS.
- Inline CSS has highest priority and overrides all other selectors.
“extenal.css” of Example-1:
Specificity Hierarchy :Every element selector has a position in the Hierarchy.
- Inline style: Inline style has highest priority.
- Identifiers(ID): ID have the second highest priority.
- Classes, pseudo-classes and attributes: Classes, pseudo-classes and attributes are come next.
- Elements and pseudo-elements: Elements and pseudo-elements have lowest priority.
- When two or more selectors have equal specificity, the last(latest) one counts.
- Universal selectors like body and inherited selectors have least specificity.
- How to create Responsive Bottom Navigation Bar using Bootstrap ?
- How to save an HTML 5 Canvas as an image on the server ?
- How to accordion scroll to top to open content in Bootstrap ?
- PHP | Imagick paintTransparentImage() Function
- p5.js | remove() Function
- p5.js | hide() Function
- p5.js | curveDetail() Function
- CSS | scale3d() Function
- p5.js | html() Function
- p5.js | size() Function
- CSS | rotateZ() Function
- p5.js | curve() function
- p5.js | position() Function
- p5.js | show() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.