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 override the CSS properties of a class using another CSS class ?
- Difference between bootstrap.css and bootstrap-theme.css
- CSS Float
- CSS | Selectors Complete Reference
- CSS | Margins and Padding
- CSS | table-layout Property
- CSS | text-align Property
- CSS | border-top-width Property
- Making a div vertically scrollable using CSS
- CSS | Percentage Value
- What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
- How to hide an element when printing a web page using CSS?
- CSS | :root Selector
- CSS | :not Selector
- CSS | isolation Property
- Parallax scrolling effect using CSS.
- How to prevent parents of floated elements from collapsing in CSS?
- CSS | Pagination
- CSS | Hue Background
- HTML | Responsive full page image using CSS
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.