HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h2>The <strong>Cascade</strong></h2>
<div id="track-labels">
<strong class="label">Normal Track</strong>
<strong class="label">Important Track</strong>
</div>
<div class='cascade-list'>
<details style='--i: 0' data-cat='origin' class='has-import'>
<summary>Origin & Importance</summary>
<div class="cat-content">
<ol layer-list='combined'>
<li>↔️ CSS Transitions</li>
<li data-side='important'>🖥 User Agent (Browser)</li>
<li data-side='important'>👥 User (Preferences)</li>
<li data-side='important'>🎨 Author (Site)</li>
<li>🔁 CSS Animations</li>
<li data-side='normal'>🎨 Author (Site)</li>
<li data-side='normal'>👥 User (Preferences)</li>
<li data-side='normal'>🖥 User Agent (Browser)</li>
</ol>
</div>
</details>
<details style='--i: 1' data-cat='context' class='has-import'>
<summary>(Shadow) Context</summary>
<div class="cat-content">
<strong class='label' data-side='important'>important</strong>
<ol layer-list='important'>
<li>🫥 Shadow DOM</li>
<li>☀️ Host (Light) DOM</li>
</ol>
<strong class='label' data-side='normal'>normal</strong>
<ol layer-list='normal'>
<li>☀️ Host (Light) DOM</li>
<li>🫥 Shadow DOM</li>
</ol>
</div>
</details>
<details style='--i: 2' data-cat='style' class='has-import'>
<summary>Element-Attached (Inline) Styles</summary>
<div class="cat-content">
<strong class='label' data-side='important'>important</strong>
<ol layer-list='important'>
<li>Inline Styles</li>
<li>Selectors</li>
</ol>
<strong class='label' data-side='normal'>normal</strong>
<ol layer-list='normal'>
<li>Inline Styles</li>
<li>Selectors</li>
</ol>
</div>
</details>
<details style='--i: 3' data-cat='layers' class='has-import'>
<summary>Cascade Layers (2022)</summary>
<div class="cat-content">
<strong class='label' data-side='important'>important</strong>
<ol layer-list='important'>
<li><i>» first-layer</i></li>
<li><i>» …</i></li>
<li><i>» last-layer</i></li>
<li><i>un-layered styles</i></li>
</ol>
<strong class='label' data-side='normal'>normal</strong>
<ol layer-list='normal'>
<li><i>un-layered styles</i></li>
<li><i>» last-layer</i></li>
<li><i>» …</i></li>
<li><i>» first-layer</i></li>
</ol>
</div>
</details>
<details style='--i: 4' data-cat='specificity'>
<summary>Selector Specificity</summary>
<div class="cat-content">
<ol layer-list='combined'>
<li><code>#id</code></li>
<li>
<code>.class</code>,
<code>:pseudo-class</code>,
<code>[attribute]</code>
</li>
<li>
<code>element</code>,
<code>::pseudo-element</code>
</li>
<li>
<code>*</code>,
<code>:where()</code>
</li>
</ol>
</div>
</details>
<details style='--i: 5' data-cat='scope'>
<summary>Scope Proximity <em>(new!)</em></summary>
<div class="cat-content">
<p>Nearest scope root (in the DOM) wins</p>
</div>
</details>
<details style='--i: 6' data-cat='order'>
<summary>Order of Appearance</summary>
<div class="cat-content">
<p>Last style wins!</p>
</div>
</details>
</div>
#track-labels {
display: flex;
justify-content: space-between;
}
.cascade-list {
display: grid;
grid-gap: 0.125em;
grid-template-columns:
repeat(6, 1fr)
auto
repeat(6, 1fr)
;
justify-content: center;
}
[data-cat] {
--h: calc(180deg + 36deg * var(--i, 0));
--col-abs: calc(var(--i, 0) + 1);
--col-neg: calc(var(--col-abs, 1) * -1);
--pad: min(5vmin, 4em);
--bg: hsl(var(--h, 0deg) 50% 75%);
--import-bg: hsl(var(--h, 0deg) 50% 25% / var(--bgi-a, 0.5));
background: var(--bg);
color: hsl(var(--h, 0deg) 15% 5%);
clip-path: polygon(0 0, 100% 0, calc(100% - var(--pad)) 100%, var(--pad) 100%);
grid-column: var(--col-abs, 1) / var(--col-neg, -1);
padding: 0.25em calc(var(--pad) + 0.5em);
}
.has-import {
background-image: linear-gradient(
to right,
transparent calc(50% - 2px),
white calc(50% - 2px) calc(50% + 2px),
var(--import-bg) calc(50% + 2px)
);
}
[open] {
--bgi-a: 1;
}
summary {
background: var(--bg);
border: thin solid;
border-radius: 3px;
cursor: pointer;
font-weight: bold;
text-shadow: 0 1px 0 var(--bg);
margin-bottom: 0.5em;
padding-inline: 1ch;
}
.label {
font-size: var(--text-small);
}
/* category content */
.cat-content {
display: grid;
grid-auto-flow: dense;
grid-template-columns: repeat(2, 1fr);
grid-gap: 0.25em 1em;
}
.cat-content > * {
grid-column: span 2;
}
/* layers */
[layer-list] {
display: grid;
font-family: 'Dank Mono', 'Courier New', Courier, monospace;
font-size: 0.8em;
grid-gap: inherit;
}
[layer-list='normal'] {
grid-column: 1;
}
[layer-list='important'] {
grid-column: 2;
}
[layer-list='combined'] {
display: grid;
grid: inherit;
grid-auto-flow: row;
}
[layer-list='combined'] li {
grid-column: var(--side, 1 / -1);
}
[data-side] {
grid-column: var(--side, 1);
}
[data-side='normal'] {
--side: 1;
}
[data-side='important'] {
--side: 2;
color: white;
}
[layer-list='important'],
[data-side='important'] {
--pre: '❗️';
--bl: 15%;
--cl: 95%;
}
/* items */
[layer-list] li {
--li-a: calc(1 - var(--li, 0) * 0.12);
align-items: center;
background: hsl(var(--h, 0deg) 50% var(--bl, 95%) / var(--li-a, 0.5));
border-inline-start: thick solid currentColor;
color: hsl(var(--h, 0deg) 5% var(--cl, 15%));
display: flex;
flex-wrap: wrap;
padding: 0.25em;
}
[layer-list] li:nth-child(2) { --li: 1; }
[layer-list] li:nth-child(3) { --li: 2; }
[layer-list] li:nth-child(4) { --li: 3; }
[layer-list] li:nth-child(5) { --li: 4; }
[layer-list] li:nth-child(6) { --li: 5; }
[layer-list] li:nth-child(7) { --li: 6; }
[layer-list] li:nth-child(8) { --li: 7; }
[layer-list] li::before {
content: var(--pre);
display: inline-block;
}
[layer-list] code {
display: inline-block;
white-space: nowrap;
}
@layer reset, base;
@layer base {
body {
--text-small: clamp(0.938rem, 0.824rem + 0.568cqi, 1.25rem);
--text-normal: clamp(1.25rem, 1.023rem + 1.136cqi, 1.875rem);
--text-large: clamp(1.35rem, 0.818rem + 2.659cqi, 2.813rem);
--text-xlarge: clamp(1.7rem, 0.784rem + 4.58cqi, 4.219rem);
--gap: clamp(12px, 0rem + 3.75cqi, 24px);
display: grid;
font-family: avenir, roboto, helvetica, sans-serif;
font-size: var(--text-normal);
grid-template-rows: auto auto 1fr;
margin: var(--gap);
}
.sr-only {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
margin: -1px;
padding: 0;
position: absolute;
width: 1px;
white-space: nowrap;
}
ol, h2 {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
}
@layer reset {
* { box-sizing: border-box; }
html { block-size: 100%; }
body {
margin: unset;
min-block-size: 100%;
}
picture { display: contents; }
img { display: block; }
img,
svg {
max-inline-size: 100%;
}
input,
button,
textarea,
select {
font: inherit;
}
}
Also see: Tab Triggers