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.
- PHP Interview Questions and Answers | Set-2
- How to Create a Tab Image Gallery ?
- XML full form
- How to create an Affix or sticky Navbar ?
- How to send email with Nodemailer using Gmail account in Node.js ?
- PHP | ReflectionExtension getFunctions() Function
- PHP | ReflectionExtension info() Function
- PHP | Imagick setLastIterator() Function
- PHP | Imagick sigmoidalContrastImage() Function
- PHP | ReflectionExtension getVersion() Function
- PHP | ReflectionClass implementsInterface() Function
- PHP | ReflectionExtension getClasses() Function
- PHP | ReflectionExtension getINIEntries() 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 firstname.lastname@example.org. 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.