In CSS, it is possible to have multiple selectors and declarations applying to elements of CSS styling, but what happens if there are conflicting styling selections? Simple: There’s a priority in what conflicting styling is applied. The priority list goes as follows from highest priority to lowest:

5) Declaration marked “!important” – These go after a declaration / style in the declaration block, such as “color: green !important;” for example. This is almost never used, as that usually means you should simplify the IDs and Classes of targeted tags and elements with declarations / styles.

4) Inline style – Style attributes inside HTML directly. Again, almost never used since there are better and more readable alternatives to styling HTML.

3) ID (#) selector

2) Class ( . ) or pseudo-class ( : ) selector

1) Element selector (p, div, li, etc.)

0) Universal selector

For ID, Class/Pseudo-Class, and Element selectors, if there are multiple conflicting styles in those selectors, then the last selector in the CSS code is applied.

By Levi

Leave a Reply

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