[type="password"],
input:focus,
:root #myApp input:required {
color: blue;
}Specificity / notebook
Specificity
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
[type="password"] {
/* 0-1-0 */
}
input:focus {
/* 0-1-1 */
}
:root #myApp input:required {
/* 1-2-1 */
}#myElement {
color: green; /* 1-0-0 - WINS!! */
}
.bodyClass .sectionClass .parentClass [id="myElement"] {
color: yellow; /* 0-4-0 */
}#myElement {
color: yellow; /* 1-0-0 */
}
#myApp [id="myElement"] {
color: green; /* 1-1-0 - WINS!! */
}:root input {
color: green; /* 0-1-1 - WINS because CLASS column is greater */
}
html body main input {
color: yellow; /* 0-0-4 */
}input.myClass {
color: yellow; /* 0-1-1 */
}
:root input {
color: green; /* 0-1-1 WINS because it comes later */
}p {
/* 0-0-1 */
}
:is(p) {
/* 0-0-1 */
}
h2:nth-last-of-type(n + 2) {
/* 0-1-1 */
}
h2:has(~ h2) {
/* 0-0-2 */
}
div.outer p {
/* 0-1-2 */
}
div:not(.inner) p {
/* 0-1-2 */
}:is(p, #fakeId) {
/* 1-0-0 */
}
h1:has(+ h2, > #fakeId) {
/* 1-0-1 */
}
p:not(#fakeId) {
/* 1-0-1 */
}
div:not(.inner, #fakeId) p {
/* 1-0-2 */
}p,
#fakeId {
span {
/* 1-0-1 */
}
}a:not(#fakeId#fakeId#fakeID) {
color: blue; /* 3-0-1 */
}<p style="color: purple">…</p>p[style*="purple"] {
color: rebeccapurple !important;
}:where(#defaultTheme) a {
/* 0-0-1 */
color: red;
}footer a {
/* 0-0-2 */
color: blue;
}@scope (.article-body) {
/* :scope img has a specificity of 0-1-0 + 0-0-1 = 0-1-1 */
:scope img {
}
}<main id="myContent">
<h1>Text</h1>
</main>#myContent h1 {
color: green; /* 1-0-1 */
}
[id="myContent"] h1 {
color: yellow; /* 0-1-1 */
}
:where(#myContent) h1 {
color: blue; /* 0-0-1 */
}#myId#myId#myId span {
/* 3-0-1 */
}
.myClass.myClass.myClass span {
/* 0-3-1 */
}:not(#fakeID#fakeId#fakeID) span {
/* 3-0-1 */
}
:is(#fakeID#fakeId#fakeID, span) {
/* 3-0-0 */
}@import "TW.css" layer();
p,
p * {
font-size: 1rem;
}@import "importantOverrides.css" layer(); @layer importantOverrides; [id="myElement"] p {
/* normal styles here */
}
@layer importantOverrides {
[id="myElement"] p {
/* important style here */
}
}body h1 {
color: green;
}
html h1 {
color: purple;
}#parent {
color: green;
}
h1 {
color: purple;
}<html lang="en">
<body id="parent">
<h1>Here is a title!</h1>
</body>
</html>#myElement input.myClass {
color: red;
} /* 1-1-1 */
input[type="password"]:required {
color: blue;
} /* 0-2-1 */
html body main input {
color: green;
} /* 0-0-4 */[id="myElement"] input.myClass {
color: red;
} /* 0-2-1 */
input[type="password"]:required {
color: blue;
} /* 0-2-1 */