CSS Hierarchy

CSS Hierarchy

CSS precedence is the hierarchical precedence of all CSS assigned to HTML tags.

What are the priorities of CSS rules used to format HTML tags? When and in what situations is the concept of !important used?

Concepts Affecting CSS Priority Order

  • Inline CSS (CSS applied directly on the tag)
  • Internal CSS (CSS applied between <style></style> tags on the same page.)
  • External CSS (CSS applied externally (from the file path or another website) with the <link> tag.)
  • Class
  • Id
  • !important

Id > Class > HTML Tag

Which CSS properties given to Class, ID and HTML tags take precedence?

If an HTML tag has ID, Class as internal CSS type, and a CSS rule that applies directly to the HTML tag, the browser will apply the CSS precedence order ID > Class > HTML Tag.

Inline > Internal > External CSS Priority

In the application of external, internal and inline CSS types, the CSS priority order will be inline > internal > external on the browser side.

Note: External CSS code can be seen in the CSS tab.

However, this prioritization only applies if each CSS implementation type is used in the same way. For example, in the use of external and internal CSS, both must be applied to the id or class or HTML tag, the order of priority will also change in different cases.