19
loading...
This website collects cookies to deliver better user experience
<p>
tag.<p> Let's Check which color is chosen by the browser </p>
p{
color: red;
}
p{
color: blue;
}
!important
rule type.<link>
tag, an embedded <style>
tag, and inline CSS as defined in an element's style attribute.<link>
that includes CSS at the top of your HTML page, then another <link>
that includes CSS at the bottom of your page, the bottom <link>
will have the most preference. The same thing happens with embedded <style>
elements, too. They get more specific, the further down the page they are.<style>
elements. If they are declared before a <link>
, the linked stylesheet's CSS will have the most specificity.!important
defined..my-element {
background: green;
background: purple;
}
<button class="btn">Hello, Specificity!</button>
button {
color: red;
}
.btn{
color: blue;
}
*{
margin: 0;
padding: 0
}
div {
color: red;
}
::selection {
color: red;
}
.my-class {
color: red;
}
:hover {
color: red;
}
[href='#'] {
color: red;
}
div:not(.my-class) {
color: red;
}
#myID {
color: red;
}
<div style="color: red"></div>
.my-class {
color: red !important; /* 10,000 points */
background: white; /* 10 points */
}