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.
<p>Examples A1 - A4 all pass.</p>
<section class="sample"><!-- Block A -->
<div>
<span class="c1 h4 w4"></span>
<span class="c1 h4 w4"></span>
<span class="c1 h4 w4"></span>
</div>
<div>
<span class="c1 h3 w4"></span>
<span class="c1 h3 w4"></span>
<span class="c1 h3 w4"></span>
</div>
<div>
<span class="c1 h2 w4"></span>
<span class="c1 h2 w4"></span>
<span class="c1 h2 w4"></span>
</div>
<div>
<span class="c1 h1 w4"></span>
<span class="c1 h1 w4"></span>
<span class="c1 h1 w4"></span>
</div>
</section>
<p>Examples B1 - B3 pass, B4 fails.</p>
<section class="sample"><!-- Block B -->
<div>
<span class="c1 h2 w3"></span>
<span class="c1 h2 w3 ml3 mr3"></span>
<span class="c1 h2 w3"></span>
</div>
<div>
<span class="c1 h2 w3"></span>
<span class="c1 h2 w3 ml2 mr2"></span>
<span class="c1 h2 w3"></span>
</div>
<div>
<span class="c1 h2 w3"></span>
<span class="c1 h2 w3 ml1 mr1"></span>
<span class="c1 h2 w3"></span>
</div>
<div>
<span class="c2 h2 w3"></span>
<span class="c2 h2 w3"></span>
<span class="c2 h2 w3"></span>
</div>
</section>
<p>Examples C1 and C2 pass, C3 and C4 fail.</p>
<section class="sample"><!-- Block C -->
<div>
<span class="c1 h2 w2"></span>
<span class="c1 h2 w2 ml3 mr3"></span>
<span class="c1 h2 w2"></span>
</div>
<div>
<span class="c1 h2 w2"></span>
<span class="c1 h2 w2 ml2 mr2"></span>
<span class="c1 h2 w2"></span>
</div>
<div>
<span class="c2 h2 w2"></span>
<span class="c2 h2 w2 ml1 mr1"></span>
<span class="c2 h2 w2"></span>
</div>
<div>
<span class="c2 h2 w2"></span>
<span class="c2 h2 w2"></span>
<span class="c2 h2 w2"></span>
</div>
</section>
<p>Example D1 passex, D2 - D4 fail.</p>
<section class="sample"><!-- Block D -->
<div>
<span class="c1 h2 w1"></span>
<span class="c1 h2 w1 ml3 mr3"></span>
<span class="c1 h2 w1"></span>
</div>
<div>
<span class="c2 h2 w1"></span>
<span class="c2 h2 w1 ml2"></span>
<span class="c2 h2 w1 ml2 mr2"></span>
<span class="c2 h2 w1"></span>
</div>
<div>
<span class="c2 h2 w1"></span>
<span class="c2 h2 w1 ml1 mr1"></span>
<span class="c2 h2 w1"></span>
</div>
<div>
<span class="c2 h2 w1"></span>
<span class="c2 h2 w1"></span>
<span class="c2 h2 w1"></span>
</div>
</section>
<p>Example E1 and E2 pass, the two outside elements of E3 and E4 fail.</p>
<section class="sample"><!-- Block E -->
<div>
<span class="c1 h2 w2"></span>
<span class="c1 h2 w4 ml3 mr3"></span>
<span class="c1 h2 w2"></span>
</div>
<div>
<span class="c1 h2 w2"></span>
<span class="c1 h2 w4 ml2 mr2"></span>
<span class="c1 h2 w2"></span>
</div>
<div>
<span class="c2 h2 w2"></span>
<span class="c1 h2 w4 ml1 mr1"></span>
<span class="c2 h2 w2"></span>
</div>
<div>
<span class="c2 h2 w2"></span>
<span class="c1 h2 w4"></span>
<span class="c2 h2 w2"></span>
</div>
</section>
<p>Example F1 and F2 pass, the inside element of F3 and F4 fail.</p>
<section class="sample"><!-- Block F -->
<div>
<span class="c1 h2 w4"></span>
<span class="c1 h2 w2 ml3 mr3"></span>
<span class="c1 h2 w4"></span>
</div>
<div>
<span class="c1 h2 w4"></span>
<span class="c1 h2 w2 ml2 mr2"></span>
<span class="c1 h2 w4"></span>
</div>
<div>
<span class="c1 h2 w4"></span>
<span class="c2 h2 w2 ml1 mr1"></span>
<span class="c1 h2 w4"></span>
</div>
<div>
<span class="c1 h2 w4"></span>
<span class="c2 h2 w2"></span>
<span class="c1 h2 w4"></span>
</div>
</section>
<p>Example G1 - G3 pass, the outer element of G4 fail.</p>
<section class="sample"><!-- Block G -->
<div>
<span class="c1 h6 w6 ml4">
<span class="c1 h4 w4 mt1 ml-n4"></span>
</span>
</div>
<div>
<span class="c1 h6 w6 ml3">
<span class="c1 h4 w4 mt1 ml-n3"></span>
</span>
</div>
<div>
<span class="c1 h6 w6 ml2">
<span class="c1 h4 w4 mt1 ml-n2"></span>
</span>
</div>
<div>
<span class="c2 h6 w6 ml1">
<span class="c1 h4 w4 mt1 ml-n1"></span>
</span>
</div>
</section>
<p>Example H1, H2, and H4 pass, the outer element of H3 fails.</p>
<section class="sample"><!-- Block H -->
<div>
<span class="c1 h6 w10">
<span class="c1 h4 w4 mt1 ml1"></span>
</span>
</div>
<div>
<span class="c1 h6 w10">
<span class="c1 h4 w4 mt1 ml2"></span>
</span>
</div>
<div>
<span class="c2 h6 w10">
<span class="c1 h4 w4 mt1 ml3"></span>
</span>
</div>
<div>
<span class="c1 h6 w10">
<span class="c1 h4 w4 mt1 ml1"></span>
<span class="c1 h4 w4 mt1"></span>
</span>
</div>
</section>
<p>Example I1 and I2 pass, I3 and I4 fail.</p>
<section class="sample"><!-- Block I -->
<div>
<span class="c1 h4 w6 ml6">
<span class="c1 h2 w6 mt1 ml-n6"></span>
</span>
</div>
<div>
<span class="c1 h4 w6 ml4">
<span class="c1 h2 w6 mt1 ml-n4"></span>
</span>
</div>
<div>
<span class="c2 h4 w6 ml2">
<span class="c2 h2 w6 mt1 ml-n2"></span>
</span>
</div>
<div>
<span class="c2 h4 w6">
<span class="c2 h2 w6 mt1"></span>
</span>
</div>
</section>
<p>Example J1 and J2 pass, J3 and J4 fail.</p>
<section class="sample"><!-- Block J -->
<div>
<span class="c1 h4 w6 ml6">
<span class="c1 h2 w6 ml-n6"></span>
</span>
</div>
<div>
<span class="c1 h4 w6 ml4">
<span class="c1 h2 w6 ml-n4"></span>
</span>
</div>
<div>
<span class="c2 h4 w6 ml2">
<span class="c2 h2 w6 ml-n2"></span>
</span>
</div>
<div>
<span class="c2 h4 w6">
<span class="c2 h2 w6"></span>
</span>
</div>
</section>
<p>Example K1 - K3 pass, the middle element of K4 fails.</p>
<section class="sample"><!-- Block K -->
<div>
<span class="c1 h4 w6 ml4">
<span class="c1 h2 w5 mt1 ml-n4"></span>
</span>
</div>
<div>
<span class="c1 h4 w6 ml4">
<span class="c1 h2 w6 mt1 ml-n4"></span>
</span>
</div>
<div>
<span class="c2 h4 w6 ml4">
<span class="c1 h2 w7 mt1 ml-n4"></span>
</span>
</div>
<div>
<span class="c2 h4 w6 ml4">
<span class="c1 h2 w8 mt1 ml-n4"></span>
</span>
</div>
</section>
<p>Example L1 and L2 pass, the outer element of L3 and L4 fail.</p>
<section class="sample"><!-- Block L -->
<div>
<span class="c1 h2 w2 rnd"></span>
<span class="c1 h2 w2 mt4 ml-n2 rnd"></span>
<span class="c1 h2 w2 mt8 ml-n2 rnd"></span>
</div>
<div>
<div class="rot30">
<span class="c1 h2 w2 rnd"></span>
<span class="c1 h2 w2 mt4 ml-n2 rnd"></span>
<span class="c1 h2 w2 mt8 ml-n2 rnd"></span>
</div>
</div>
<div>
<span class="c1 h2 w2 rnd"></span>
<span class="c1 h2 w2 mt3 ml1 rnd"></span>
<span class="c1 h2 w2 mt6 ml1 rnd"></span>
</div>
<div>
<span class="c1 h2 w2"></span>
<span class="c2 h2 w2 mt3 ml1 rnd"></span>
<span class="c1 h2 w2 mt6 ml1"></span>
</div>
</section>
<p>Example M1 & M2 pass, the outer element of M3 fail, as do both elements of M4.</p>
<section class="sample"><!-- Block M -->
<div>
<span class="c1 h6 w6 ml3 rnd">
<span class="c1 h4 w4 mt1 ml-n3"></span>
</span>
</div>
<div>
<span class="c1 h6 w6 ml2 rnd">
<span class="c1 h4 w4 mt1 ml-n2"></span>
</span>
</div>
<div>
<span class="c2 h6 w6 ml1 rnd">
<span class="c1 h4 w4 mt1 ml-n1"></span>
</span>
</div>
<div>
<span class="c2 h6 w6 ml1 rnd">
<span class="c2 h2 w2 mt2 ml1"></span>
</span>
</div>
</section>
<p>Example N1 & N2 pass, the outer element of N3 & N4 fail.</p>
<section class="sample"><!-- Block N -->
<div>
<span class="c1 h6 w10 rnd">
<span class="c1 h4 w4 mt1 ml1"></span>
</span>
</div>
<div>
<span class="c1 h6 w10 rnd">
<span class="c1 h4 w4 mt1 ml2"></span>
</span>
</div>
<div>
<span class="c2 h6 w10 rnd">
<span class="c1 h4 w4 mt1 ml3"></span>
</span>
</div>
<div>
<span class="c1 h6 w10 rnd">
<span class="c2 h2 w2 mt2 ml4"></span>
</span>
</div>
</section>
<p>Element O1 and O4 pass, the inner element of O2 and O3 fail.</p>
<section class="sample"><!-- Block O -->
<div>
<svg height="24" width="24">
<path fill="url(#c1)" d="M0 0 L12 8 L24 0 L16 12 L24 24 L12 16 L0 24 L8 12 L0 0" />
</svg>
<span class="c1 h4 w4"></span>
<svg height="24" width="24">
<path fill="url(#c1)" d="M0 0 L12 8 L24 0 L16 12 L24 24 L12 16 L0 24 L8 12 L0 0" />
</svg>
</div>
<div>
<span class="c1 h6 w10">
<svg height="24" width="24" class="mt1 ml1">
<path fill="url(#c2)" d="M0 0 L12 8 L24 0 L16 12 L24 24 L12 16 L0 24 L8 12 L0 0" />
</svg>
</span>
</div>
<div>
<span class="c1 h6 w10">
<svg height="24" width="24" class="mt1 ml1">
<path fill="url(#c2)" d="M0 0 L12 6 L24 0 L18 12 L24 24 L12 18 L0 24 L6 12 L0 0" />
</svg>
</span>
</div>
<div>
<span class="c1 h8 w11">
<svg height="36" width="36" class="mt1 ml1">
<path fill="url(#c1)" d="M0 0 L18 6 L36 0 L30 18 L36 36 L18 30 L0 36 L6 18 L0 0" />
</svg>
</span>
</div>
</section>
<p>Example P1 and P2 pass. P3 fails only for the bottom target, P4 fails.</p>
<section class="sample"><!-- Block P -->
<div>
<span class="c1 h2 w6"></span>
<span class="c1 h2 w6 mt3"></span>
</div>
<div>
<span class="c1 h2 w6"></span>
<span class="c1 h2 w6 mt3 ml-n1"></span>
</div>
<div>
<span class="c1 h2 w10"></span>
<span class="c2 h2 w6 mt3 ml-n6"></span>
</div>
<div>
<span class="c2 h2 w10"></span>
<span class="c2 h2 w10 mt3 ml-n10"></span>
</div>
</section>
<p><stong>With the proposed new definition:</strong> Q1 passes, Q2 - Q4 fail.</p>
<section class="sample"><!-- Block Q -->
<div>
<span class="c1 h2 w6"></span>
<span class="c1 h2 w6 mt3"></span>
</div>
<div>
<span class="c2 h2 w6"></span>
<span class="c2 h2 w6 mt3 ml-n1"></span>
</div>
<div>
<span class="c2 h2 w10"></span>
<span class="c2 h2 w6 mt3 ml-n6"></span>
</div>
<div>
<span class="c2 h2 w10"></span>
<span class="c2 h2 w10 mt3 ml-n10"></span>
</div>
</section>
<svg>
<defs>
<linearGradient id="c1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color: lightgreen; stop-opacity:1" />
<stop offset="100%" style="stop-color: darkgreen; stop-opacity:1" />
</linearGradient>
<linearGradient id="c2" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color: darkred; stop-opacity:1" />
<stop offset="100%" style="stop-color: pink; stop-opacity:1" />
</linearGradient>
</defs>
</svg>
p {
font-size: 14px;
margin: 1.3em 0 .3em;
}
.sample { display: flex; }
.sample > div {
outline: solid 1px #ddd;
padding: 12px 6px;
flex-basis: 95px;
justify-content: center;
}
.sample div {
position: relative;
display: flex;
}
.sample > div span {
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, .4),
inset 2px 2px 0 rgba(0, 0, 0, .4);
display: flex;
z-index: 1;
}
.sample p {
position: absolute;
font-size: 10px;
top: -9px;
left: 3px;
color: #333;
}
.rnd { border-radius: 50%; }
.rot30 { transform: rotate(-30deg); }
svg path {
stroke: rgba(0, 0, 0, 0.4);
stroke-width: 2px;
}
/* color */
.c1 { background: linear-gradient(90deg, darkgreen 0%, lightgreen 100%); }
.c2 { background: linear-gradient(90deg, pink 0%, darkred 100%); }
/* height */
.h1 { height: 6px; }
.h2 { height: 12px; }
.h3 { height: 18px; }
.h4 { height: 24px; }
.h6 { height: 36px; }
.h7 { height: 42px; }
.h8 { height: 48px; }
.h10 { height: 60px; }
/* With */
.w1 { width: 6px; }
.w2 { width: 12px; }
.w3 { width: 18px; }
.w4 { width: 24px; }
.w5 { width: 30px; }
.w6 { width: 36px; }
.w7 { width: 42px; }
.w8 { width: 48px; }
.w10 { width: 60px; }
.w11 { width: 66px; }
/* Margins */
.m4-n2 { margin-right: -12px; }
.m4-n1 { margin-right: -6px; }
.mr1 { margin-right: 6px; }
.mr2 { margin-right: 12px; }
.mr3 { margin-right: 18px; }
.mr4 { margin-right: 24px; }
.ml-n10 { margin-left: -60px; }
.ml-n8 { margin-left: -48px; }
.ml-n6 { margin-left: -36px; }
.ml-n4 { margin-left: -24px; }
.ml-n3 { margin-left: -18px; }
.ml-n2 { margin-left: -12px; }
.ml-n1 { margin-left: -6px; }
.ml1 { margin-left: 6px; }
.ml2 { margin-left: 12px; }
.ml3 { margin-left: 18px; }
.ml4 { margin-left: 24px; }
.ml5 { margin-left: 30px; }
.ml6 { margin-left: 36px; }
.mt-n1 { margin-top: -6px; }
.mt1 { margin-top: 6px; }
.mt2 { margin-top: 12px; }
.mt3 { margin-top: 18px; }
.mt4 { margin-top: 24px; }
.mt5 { margin-top: 30px; }
.mt6 { margin-top: 36px; }
.mt8 { margin-top: 48px; }
.mb-n1 { margin-bottom: -6px; }
.mb1 { margin-bottom: 6px; }
.mb2 { margin-bottom: 12px; }
.mb3 { margin-bottom: 18px; }
.mb4 { margin-bottom: 24px; }
.mb5 { margin-bottom: 30px; }
.mb6 { margin-bottom: 36px; }
document.querySelectorAll('.sample').forEach((section, letter) => {
Array.from(section.children).forEach((div, num) => {
const p = document.createElement('p')
p.innerText = String.fromCharCode(65 + letter) + (num+1)
div.prepend(p)
})
})
Also see: Tab Triggers