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.
<table>
<thead>
<tr>
<th>Type</th>
<th>Expected</th>
<th>Actual</th>
</tr>
</thead>
<tbody>
<tr class="translate-px">
<th>translateX( calc(20 * 1px))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="translate-vmin">
<th>translateX( calc(2 * 1vmin))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="translate-percent">
<th>translateX( calc(200 * 1%))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="width-px">
<th>width: calc(50 * 1px)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="width-ch">
<th>width: calc(6 * 1ch)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="rotate-deg">
<th>rotate( calc(45 * 1deg))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="rotate-turn">
<th>rotate( calc(.125 * 1turn))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="rotate-combo">
<th>rotate( calc(45deg + .5turn))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="opacity">
<th>opacity( calc(.25 * 1))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="scale-x">
<th>scaleX( calc(2 * 1))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="font-size">
<th>font-size: calc(2 * 1rem)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="font-size2">
<th>font-size: calc(200 * 1%)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="line-height">
<th>line-height: calc(3 * 1)</th>
<td><p> </p></td>
<td><p> </p></td>
</tr>
<tr class="gradient-stop">
<th>linear-gradient(to right, #45cdd4 calc(30 * 1%), transparent)</th>
<td><p> </p></td>
<td><p> </p></td>
</tr>
<tr class="hue-deg">
<th>hsl( calc(50 * 2), 50%, 50%)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="hsl-saturation">
<th>hsl( 100, calc(100 * 1%), 50%)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="color-g">
<th>rgb( 80, calc(255 * 1), 80)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="color-ga">
<th>rgba( 80, 255, 80, calc(1 * .5))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="cubic add">
<th>cubic-bezier( calc(0 + .25), 1, 0, 1)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="cubic multiply">
<th>cubic-bezier( calc(1 * .25), 1, 0, 1)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="transition-duration">
<th>*-duration: calc(1000 * 1ms)</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="filter-blur">
<th>blur( calc(.5 * 2px))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
<tr class="filter-hue">
<th>hue-rotate( calc(90 * 1deg))</th>
<td><p></p></td>
<td><p></p></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Started this as I was seeing what appeared to be broken CSS Variables... but turned out to be a misunderstanding on how calc is implemented in browsers. Some properties allow you to take any unitless number and multiply it by a number+unit to get a final unit value... others do not. As of Firefox 57, everything in this test works except the colors. Safari and Chrome support all of the ones I've tested. Edge does fine with px, vmin, and other linear distance units... but does not seem to handle degrees, unitless, etc. (except in colors, interestingly)</td>
</tr>
</tfoot>
</table>
p {
width: 1em;
height: 1em;
border: .15rem solid #45cdd4;
display: inline-block;
}
:not(tfoot) > tr > td {
background: radial-gradient(circle at center center, black 0, black 1px, transparent 2px) center center no-repeat;
}
.width-px td:first-of-type p {
width: 50px;
}
.width-px td:nth-of-type(2) p {
width: calc(50 * 1px);
}
.width-ch td:first-of-type p {
width: 6ch;
}
.width-ch td:nth-of-type(2) p {
width: calc(6 * 1ch);
}
.translate-px td:first-of-type p {
transform: translateX(20px);
}
.translate-px td:nth-of-type(2) p {
transform: translateX(calc(20 * 1px));
}
.translate-vmin td:first-of-type p {
transform: translateX(2vmin);
}
.translate-vmin td:nth-of-type(2) p {
transform: translateX(calc(2 * 1vmin));
}
.translate-percent td:first-of-type p {
transform: translateX(200%);
}
.translate-percent td:nth-of-type(2) p {
transform: translateX(calc(200 * 1%));
}
.rotate-deg td:first-of-type p {
transform: rotate(45deg);
}
.rotate-deg td:nth-of-type(2) p {
transform: rotate(calc(45 * 1deg));
}
.rotate-turn td:first-of-type p {
transform: rotate(.125turn);
}
.rotate-turn td:nth-of-type(2) p {
transform: rotate(calc(.125 * 1turn));
}
.rotate-combo td:first-of-type p {
transform: rotate(.625turn);
}
.rotate-combo td:nth-of-type(2) p {
transform: rotate(calc(45deg + .5turn));
}
.opacity td:first-of-type p {
opacity: .25;
}
.opacity td:nth-of-type(2) p {
opacity: calc(.25 * 1);
}
.scale-x td:first-of-type p {
transform: scaleX(2);
}
.scale-x td:nth-of-type(2) p {
transform: scaleX(calc(2 * 1));
}
.font-size td:first-of-type p {
font-size: 2rem;
}
.font-size td:nth-of-type(2) p {
font-size: calc(2 * 1rem);
}
.font-size2 td:first-of-type p {
font-size: 200%;
}
.font-size2 td:nth-of-type(2) p {
font-size: calc(200 * 1%);
}
.line-height td:first-of-type p {
line-height: 3;
height: auto;
}
.line-height td:nth-of-type(2) p {
line-height: calc(3 * 1);
height: auto;
}
.gradient-stop td:first-of-type p {
background: linear-gradient(to right, #45cdd4 30%, transparent);
}
.gradient-stop td:nth-of-type(2) p {
background: linear-gradient(to right, #45cdd4 calc(30 * 1%), transparent);
}
.hue-deg td:first-of-type p {
background: hsl(100, 50%, 50%);
}
.hue-deg td:nth-of-type(2) p {
background: hsl(calc(50 * 2), 50%, 50%);
}
.hsl-saturation td:first-of-type p {
background: hsl(100, 100%, 50%);
}
.hsl-saturation td:nth-of-type(2) p {
background: hsl(100, calc(100 * 1%), 50%);
}
.color-g td:first-of-type p {
background: rgb(80, 255, 80);
}
.color-g td:nth-of-type(2) p {
background: rgb(80, calc(255 * 1), 80);
}
.color-ga td:first-of-type p {
background: rgba(80, 255, 80, .5);
}
.color-ga td:nth-of-type(2) p {
background: rgba(80, 255, 80, calc(.5 * 1));
}
.cubic p {
animation: go 1000ms infinite alternate;
}
.cubic.add td:first-of-type p {
animation-timing-function: cubic-bezier(.25, 1, 0, 1)
}
.cubic.add td:nth-of-type(2) p {
animation-timing-function: cubic-bezier(calc(0 + .25), 1, 0, 1);
}
.cubic.multiply td:first-of-type p {
animation-timing-function: cubic-bezier(.25, 1, 0, 1)
}
.cubic.multiply td:nth-of-type(2) p {
animation-timing-function: cubic-bezier(calc(1 * .25), 1, 0, 1);
}
.transition-duration p {
animation: go 0ms infinite alternate linear;
}
.transition-duration td:first-of-type p {
animation-duration: 1000ms;
}
.transition-duration td:nth-of-type(2) p {
animation-duration: calc(1000 * 1ms);
}
.filter-blur td:first-of-type p {
filter: blur(1px);
}
.filter-blur td:nth-of-type(2) p {
filter: blur(calc(.5 * 2px));
}
.filter-hue td:first-of-type p {
filter: hue-rotate(90deg);
}
.filter-hue td:nth-of-type(2) p {
filter: hue-rotate(calc(90 * 1deg));
}
@keyframes go {
from {
transform: translateX(-10vmin)
}
to {
transform: translateX(10vmin)
}
}
body {
font-family: system-ui, -apple-system, 'Segoe UI', 'Roboto', sans-serif;
min-height: 100vh;
background: hsl(230, 10%, 94%);
}
table {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
th, td {
width: 25%;
border: 1px solid grey;
text-align: center;
vertical-align: center;
padding: 1rem .25rem;
}
th:first-child,
td:first-child {
width: 50%;
}
th, tfoot td {
font-size: .875rem;
}
Also see: Tab Triggers