codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › CSS specificity

CSS specificity

Which rule wins.

Inline styles beat ids, ids beat classes, classes beat tags. With equal specificity, the later rule wins.

Example code

<style>
p{color:blue}.k{color:green}#i{color:red}
</style>
<p class='k' id='i'>Red: id wins</p><p class='k'>Green: class beats tag</p>

Run this code in the online editor

← CSS inheritanceCSS !important →