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.
<div class="controls">
<label for="box">Apply transform-box</label>
<input type="checkbox" id="box" checked>
</div>
<button>
<svg aria-hidden="true" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none">
<rect width="18" height="1.5" fill=red ry="0.75" x="3" y="6.25" />
<rect width="18" height="1.5" fill=red ry="0.75" x="3" y="11.25" />
<rect width="18" height="1.5" fill=red ry="0.75" x="3" y="16.25" />
</svg>
</button>
* {
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
min-height: 100vh;
background: hsl(0 0% 6%);
}
button {
width: 280px;
aspect-ratio: 1;
display: grid;
place-items: center;
padding: 0;
scale: 1;
background: transparent;
border: 0;
border-radius: 50%;
transition: background 0.2s;
cursor: pointer;
}
button:is(:hover, :focus-visible) {
background: hsl(0 0% 16%);
}
button:is(:focus-visible) {
outline-color: hsl(320 80% 50% / 0.5);
outline-offset: 1rem;
outline-width: 4px;
}
button svg:first-of-type {
width: 65%;
}
button rect {
transform-box: fill-box;
transform-origin: 50% 50%;
fill: hsl(0 0% 98%);
}
.unset rect {
transform-box: unset;
}
[aria-pressed=true] rect {
transition: translate 0.2s, rotate 0.2s 0.3s;
}
rect {
transition: rotate 0.2s 0s, translate 0.2s 0.2s;
}
[aria-pressed=true] rect:nth-of-type(1) {
translate: 0 333%;
rotate: -45deg;
}
[aria-pressed=true] rect:nth-of-type(2) {
rotate: 45deg;
}
[aria-pressed=true] rect:nth-of-type(3) {
translate: 0 -333%;
rotate: 45deg;
}
[aria-pressed=true] svg {
rotate: 90deg;
transition: rotate 1s 0.4s;
}
@supports (--custom: linear()) {
:root {
--elastic-out: linear(
0, 0.2178 2.1%, 1.1144 8.49%,
1.2959 10.7%, 1.3463 11.81%,
1.3705 12.94%, 1.3726, 1.3643 14.48%,
1.3151 16.2%, 1.0317 21.81%,
0.941 24.01%, 0.8912 25.91%,
0.8694 27.84%, 0.8698 29.21%,
0.8824 30.71%, 1.0122 38.33%, 1.0357,
1.046 42.71%, 1.0416 45.7%,
0.9961 53.26%, 0.9839 57.54%,
0.9853 60.71%, 1.0012 68.14%,
1.0056 72.24%, 0.9981 86.66%, 1
);
--elastic-in-out: linear(
0, 0.0009 8.51%, -0.0047 19.22%,
0.0016 22.39%, 0.023 27.81%,
0.0237 30.08%, 0.0144 31.81%,
-0.0051 33.48%, -0.1116 39.25%,
-0.1181 40.59%, -0.1058 41.79%, -0.0455,
0.0701 45.34%, 0.9702 55.19%,
1.0696 56.97%, 1.0987 57.88%,
1.1146 58.82%, 1.1181 59.83%,
1.1092 60.95%, 1.0057 66.48%,
0.986 68.14%, 0.9765 69.84%,
0.9769 72.16%, 0.9984 77.61%,
1.0047 80.79%, 0.9991 91.48%, 1
);
}
[aria-pressed=true] svg {
transition-timing-function: var(--elastic-out);
}
}
.controls {
position: fixed;
top: 1rem;
right: 1rem;
display: flex;
gap: 1rem;
color: hsl(0 0% 98%);
accent-color: hsl(0 0% 100%);
}
const TOGGLE = document.querySelector('button')
const HANDLE_TOGGLE = () => {
TOGGLE.setAttribute('aria-pressed', TOGGLE.matches('[aria-pressed=true]') ? false : true)
}
TOGGLE.addEventListener('click', HANDLE_TOGGLE)
const INPUT = document.querySelector('input')
const APPLY_TRANSFORM_BOX = () => {
TOGGLE.classList.toggle('unset')
}
INPUT.addEventListener('change', APPLY_TRANSFORM_BOX)
Also see: Tab Triggers