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">
<button id="colors" class="btn-colors" aria-label="Change colors" title="Change colors">
<svg data-icon="color" viewBox="0 0 512 512" width="100">
<path d="M8 256c0 136.966 111.033 248 248 248s248-111.034 248-248S392.966 8 256 8 8 119.033 8 256zm248 184V72c101.705 0 184 82.311 184 184 0 101.705-82.311 184-184 184z" />
</svg>
</button>
<button id="fullscreen" class="btn-fullscreen" aria-label="Toggle fullscreen" title="Toggle fullscreen">
<svg data-icon="open" viewBox="0 0 448 512" width="100">
<path d="M448 344v112a23.94 23.94 0 0 1-24 24H312c-21.39 0-32.09-25.9-17-41l36.2-36.2L224 295.6 116.77 402.9 153 439c15.09 15.1 4.39 41-17 41H24a23.94 23.94 0 0 1-24-24V344c0-21.4 25.89-32.1 41-17l36.19 36.2L184.46 256 77.18 148.7 41 185c-15.1 15.1-41 4.4-41-17V56a23.94 23.94 0 0 1 24-24h112c21.39 0 32.09 25.9 17 41l-36.2 36.2L224 216.4l107.23-107.3L295 73c-15.09-15.1-4.39-41 17-41h112a23.94 23.94 0 0 1 24 24v112c0 21.4-25.89 32.1-41 17l-36.19-36.2L263.54 256l107.28 107.3L407 327.1c15.1-15.2 41-4.5 41 16.9z" />
</svg>
<svg data-icon="close" viewBox="0 0 512 512" width="100">
<path d="M200 288H88c-21.4 0-32.1 25.8-17 41l32.9 31-99.2 99.3c-6.2 6.2-6.2 16.4 0 22.6l25.4 25.4c6.2 6.2 16.4 6.2 22.6 0L152 408l31.1 33c15.1 15.1 40.9 4.4 40.9-17V312c0-13.3-10.7-24-24-24zm112-64h112c21.4 0 32.1-25.9 17-41l-33-31 99.3-99.3c6.2-6.2 6.2-16.4 0-22.6L481.9 4.7c-6.2-6.2-16.4-6.2-22.6 0L360 104l-31.1-33C313.8 55.9 288 66.6 288 88v112c0 13.3 10.7 24 24 24zm96 136l33-31.1c15.1-15.1 4.4-40.9-17-40.9H312c-13.3 0-24 10.7-24 24v112c0 21.4 25.9 32.1 41 17l31-32.9 99.3 99.3c6.2 6.2 16.4 6.2 22.6 0l25.4-25.4c6.2-6.2 6.2-16.4 0-22.6L408 360zM183 71.1L152 104 52.7 4.7c-6.2-6.2-16.4-6.2-22.6 0L4.7 30.1c-6.2 6.2-6.2 16.4 0 22.6L104 152l-33 31.1C55.9 198.2 66.6 224 88 224h112c13.3 0 24-10.7 24-24V88c0-21.3-25.9-32-41-16.9z" />
</svg>
</button>
</div>
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
display: grid;
place-content: center;
grid-template-areas: "body";
overflow: hidden;
}
body::before,
body::after {
--size: 150vmax;
--duration: 8s;
content: "";
grid-area: body;
width: var(--size);
height: var(--size);
animation-timing-function: linear;
animation-iteration-count: infinite;
}
body::before {
animation-name: rotate;
animation-duration: var(--duration);
background: linear-gradient(to left, var(--palette));
}
body::after {
animation-name: rotate, fade;
animation-duration: calc(var(--duration) / 2), var(--duration);
background: linear-gradient(to right, var(--palette));
}
@keyframes rotate {
to {
transform: rotate(1turn);
}
}
@keyframes fade {
50% {
opacity: 0;
}
}
/* Gradients generated at https://learnui.design/tools/gradient-generator.html */
body {
--rotate: 0deg;
--palette: #1f005c, #5b0060, #870160, #ac255e, #ca485c, #e16b5c, #f39060,
#ffb56b;
}
[data-color="1"] {
--rotate: 90deg;
--palette: #004466, #006080, #007e90, #009b97, #29b794, #74d18b, #b7e881,
#fffb80;
}
[data-color="2"] {
--rotate: 180deg;
--palette: #f3ff17, #ffde00, #ffb900, #ff8f39, #ff6062, #ff298b, #ff00b5, #ff1fdd;
}
[data-color="3"] {
--rotate: 270deg;
--palette: #054ce6, #0072ff, #008fff, #00a5ff, #00b8e4, #00c9bb, #00d890, #36e367;
}
/* Controls */
.controls {
--offset: 0.5rem;
position: fixed;
top: var(--offset);
left: var(--offset);
right: var(--offset);
width: calc(100% - var(--offset) * 2);
display: flex;
justify-content: space-between;
padding-left: min(5vmin, env(safe-area-inset-left));
padding-right: min(5vmin, env(safe-area-inset-right));
z-index: 1;
}
button {
display: flex;
align-items: center;
font-family: system-ui;
font-size: inherit;
padding: 1rem;
color: white;
fill: currentcolor;
background-color: transparent;
border: none;
cursor: pointer;
touch-action: manipulation;
}
button:active {
transform: translateY(1px);
}
.btn-colors [data-icon] {
width: 1.4em;
transform: rotate(var(--rotate));
}
.btn-fullscreen [data-icon] {
width: 1.2em;
}
[data-icon="close"] {
display: none;
}
.is-fullscreen [data-icon="open"] {
display: none;
}
.is-fullscreen [data-icon="close"] {
display: block;
}
const btnFullScreen = document.getElementById("fullscreen");
const btnColors = document.getElementById("colors");
btnFullScreen.addEventListener("click", toggleFullScreen);
btnColors.addEventListener("click", toggleColorClass);
document.addEventListener("fullscreenchange", toggleFullScreenClass);
document.addEventListener("webkitfullscreenchange", toggleFullScreenClass);
function toggleColorClass() {
document.body.dataset.color == 3 ? document.body.dataset.color = 0 : document.body.dataset.color++;
}
function toggleFullScreenClass() {
document.body.classList.toggle("is-fullscreen", document.fullscreenElement || document.webkitFullscreenElement);
}
function toggleFullScreen() {
if (!document.fullscreenElement && !document.webkitFullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
function init() {
document.body.dataset.color = 0;
if (!document.fullscreenEnabled) {
btnFullScreen.remove();
}
}
init();
Also see: Tab Triggers