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="grid">
<p>Compressed Size: <i class="size">Waiting</i></p>
<p>Build Time: <i class="time">Waiting</i></p>
<button class="btn">Compress (Ctrl+Enter)</button>
</div>
<div class="lorem" contenteditable>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed tristique lacus. Duis leo arcu, auctor in mattis et, accumsan eget nisl. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi venenatis euismod quam, eu rutrum eros pellentesque quis. Integer imperdiet semper dignissim. Integer efficitur nisi at augue tempus porta. In in gravida dui. Sed ac diam erat. Quisque varius mauris vel ipsum blandit, vel congue lectus elementum. Etiam consectetur mi purus, ut semper magna aliquet quis. Nunc congue dignissim est, non malesuada felis aliquet id. Donec at neque ac enim imperdiet convallis. Curabitur tincidunt dapibus metus non tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus vitae gravida enim. Sed lacinia lacus massa, ac mattis felis accumsan et.
Integer lobortis sapien quis mi cursus ornare. Mauris lacinia justo eu eleifend ornare. Vivamus efficitur augue vitae nunc euismod, sed feugiat nunc pharetra. Praesent non sem tellus. Donec id felis non purus vulputate feugiat at nec ante. Suspendisse condimentum justo sem, vel vehicula mauris pulvinar id. Phasellus risus ex, venenatis sed bibendum eu, faucibus quis ipsum. Curabitur suscipit quis massa et dignissim. Nunc ac odio mauris. Duis turpis lectus, tempus dapibus ante vel, pharetra malesuada turpis. Aenean feugiat tellus eu mi fringilla, in pulvinar diam vulputate. Mauris lobortis neque eu nibh tempor, eget pharetra massa consectetur. Etiam luctus mauris a ligula convallis tincidunt. Praesent fringilla cursus est, sit amet vehicula dui facilisis et. Mauris a metus elit.
Vestibulum pellentesque, enim ac vulputate commodo, risus urna ultrices mauris, eget euismod odio libero et eros. Integer faucibus orci sed imperdiet rhoncus. Proin eros eros, ornare ut gravida et, ultrices sed elit. Vestibulum magna neque, lobortis id auctor eu, malesuada non est. Aliquam faucibus a dolor sit amet placerat. Morbi malesuada leo elit. Maecenas tempor dapibus dapibus. Sed ultricies dapibus nisi et rutrum. Vivamus ipsum eros, tincidunt ut enim at, finibus condimentum neque. Nullam sit amet diam eu ipsum tristique sollicitudin. Sed facilisis lectus est, eget mattis erat aliquet et. Cras sed urna volutpat, consequat velit sed, elementum eros. In vel nibh quis sapien mollis fermentum.
Vestibulum non iaculis velit. Vestibulum fermentum eros non massa dignissim, fermentum feugiat nunc congue. Vestibulum pulvinar augue eget tempus congue. Aliquam maximus elementum diam. Ut sit amet porttitor risus. In hac habitasse platea dictumst. Suspendisse a viverra odio, et hendrerit dolor. Suspendisse nec suscipit nibh.
Phasellus quis odio ex. Ut pharetra dapibus nisi, et dapibus orci eleifend sed. Aliquam sit amet commodo orci. Duis faucibus, risus quis sagittis finibus, magna nunc accumsan sapien, ac tincidunt mauris odio fermentum ex. Nunc sed justo ipsum. Nullam viverra ante ac lorem facilisis, ac sodales velit iaculis. Donec nec urna ipsum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque lacinia molestie aliquet. Donec eget felis in leo auctor tincidunt.
Generated 5 paragraphs, 473 words, 3187 bytes of Lorem Ipsum.</div>
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
}
}
.grid,
.lorem {
padding: 10px;
}
.grid {
display: grid;
gap: 10px;
font-variant-numeric: tabular-nums;
grid-auto-flow: column;
justify-content: space-around;
}
.lorem {
border: 1px solid;
background-color: rgba(255, 255, 255, 0.15);
padding: 8px 12px;
margin: 10px;
resize: both;
height: 500px;
overflow: auto;
scrollbar-gutter: stable;
}
import prettyBytes from "https://cdn.skypack.dev/pretty-bytes?min";
import {
gzipSync,
strToU8,
compress
} from "https://cdn.skypack.dev/fflate?min";
let timeFormatter = new Intl.RelativeTimeFormat("en", {
style: "narrow",
numeric: "auto"
});
let content = document.querySelector(".lorem");
let time = document.querySelector(".time");
let size = document.querySelector(".size");
let asyncCompress = (buf, opts = {}) => {
return new Promise((resolve, reject) => {
// The default compression method is gzip
// Increasing mem may increase performance at the cost of memory
// The mem ranges from 0 to 12, where 4 is the default
compress(buf, opts, (err, data) => {
if (err) reject(err);
resolve(data);
});
});
};
let compressFn = () => {
const startTime = Date.now();
const buf = strToU8(content.textContent.trim());
const timeout = setTimeout(() => {
time.textContent = "Loading...";
size.textContent = "Loading...";
}, 100);
(async () => {
const data = await asyncCompress(buf, { level: 9 });
const gzipSize = prettyBytes(data.length);
clearTimeout(timeout);
time.textContent = timeFormatter.format(
(Date.now() - startTime) / 1000,
"seconds"
);
size.textContent = gzipSize;
console.log(gzipSize);
})();
};
compressFn();
let button = document.querySelector(".btn");
button.addEventListener("click", compressFn);
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && e.keyCode === 13) {
compressFn();
}
});
Also see: Tab Triggers