Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container fluid">
  <h1>:where() and specificity</h1>
  <h2>The h2s being overridden</h2>
  <p>In this example, I'm using fluid text styles as a default for the all body copy, h1, and h2 tags. I am using <code>:where(.fluid)</code> selector on the body and the h2, but I'm using plain <code>.fluid</code> selector on the h1 tag. Anything <code>:where()</code> is computed with 0 specificity.</p>
  <h2>Check the CSS lines 22—43</h2>
  <p>Lower in the CSS file, I'm "overriding" the h1 and h2 to change their colors and size, but you'll notice that the h2 tags are the only ones that change. If you check at lines 22—43, you'll see that the the h2 selectors are more specific than the <code>:where(.fluid) h2</code> selectors. That is why we have static h2 sizing and different colors from our initial declaration. You can find more infomation about this on <a href="https://leininger.tech/words/where-pseudo-class/">my blog</a>.</p>
</div>
              
            
!

CSS

              
                /* specificity score: 0, 0, 1 */
body {
  font-size: 1rem;
  color: lightslategray;
}

/* specificity score: 0, 0, 1 */
body :where(.fluid) {
  font-size: clamp(1rem, calc(0.88rem + 0.51vw), 1.25rem);
}

/* specificity score: 0, 0, 1 */
h1 {
  font-size: 2rem;
  color: RebeccaPurple;
}
h2 {
  font-size: 1.5rem;
  color: RebeccaPurple;
}

/* specificity score: 0, 1, 1 -- pseudo-class */
.fluid h1 {
  font-size: clamp(1.6rem, calc(0.9rem + 2.99vw), 3.05rem);
  color: DarkCyan;
}

/* specificity score: 0, 0, 1 */
:where(.fluid) h2 {
  color: DarkCyan;
  font-size: clamp(1.42rem, calc(0.93rem + 2.1vw), 2.44rem);
}

/* specificity score: 0, 0, 1 this loses to .fluid h1 */
h1 {
  font-size: 4rem;
  color: darkslategray;
}
/* specificity score: 0, 0, 1 this overrides :where(.fluid) h2 */
h2 {
  font-size: 3rem;
  color: darkslategray;
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// Visual help!
body {
  line-height: 1.5;
}
.container {
  max-width: 70ch;
  margin-inline: auto;
  padding-inline: 1.5rem;
}
code {
  background-color: #e6e6e6;
  border-radius: 0.25em;
  color: darkslategray;
  font-size: 0.95em;
  padding: 0.05em 0.125em;
}
::selection {
  background-color: darkcyan;
  color: white;
}
/* :is() takes the highest specificity score of the included selectors.
This has a specificity score: 0, 0, 1 */
:is(h1, h2) {
  line-height: 1.1;
  margin-bottom: 0;
}
a:where(:not([class])) {
  border-radius: 0.25rem;
  box-decoration-break: clone;
  color: darkcyan;
  text-decoration: underline;
  text-underline-offset: 2px;
  outline-color: lightseagreen;
}
a:where(:not([class])):where(:hover, :focus, :focus-visible) {
  color: rebeccapurple;
  text-decoration-color: darkcyan;
}
a:where(:not([class])):where(:focus-visible) {
  outline-offset: 0.25rem;
  outline-style: solid;
  outline-width: 2px;
}

              
            
!

JS

              
                
              
            
!
999px

Console