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.
<!--
As always, there’s probably a better way to do all this, but…
IOAFCP (It's Only a F***ing CodePen), so relax.
However, if you have constructive feedback, I'd love to hear it. I learn a lot from my mistakes and poor life choices.
Adopt, don't shop 🐈
-->
// I use Recursive for almost everything. I even use it in my coffee.
// https://github.com/arrowtype/recursive
// Thank you Stephen Nixon for font-weight fix. I didn't have it in there and it was fauxing the bold. Amateur mistake.
@font-face {
font-family: recursive;
font-display: swap;
font-weight: 300 1000;
src: url('https://assets.codepen.io/2468711/Recursive_VF_1.047.woff2') format('woff2');
}
// CSS variables are so cool. We’re going to change these in the script.
:root {
--font-size: 1rem;
--font-weight: 100;
--top: 0;
--left: 0;
--color: #f67809;
--opacity: .1;
--background-color: #060606;
}
html {
font-family: recursive, sans-serif;
font-weight: 600;
font-variation-settings:
'MONO' 1; // I never had mono… or chicken pox.
}
body {
position: relative;
height: 100vh;
overflow: hidden;
background-color: var(--background-color);
position: relative;
// We’re going to put a texture over the whole shebang.
// It looks cool without it too.
&::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
// CodePen assets are neat.
background-image: url(https://assets.codepen.io/2468711/cloth-cover.jpg);
background-size: cover;
opacity: .2;
}
}
// This is the thing the choosen (LOL “choosen”) glyphs get plopped into… or is it “in to”? Whatever.
// The script will change these variables (CSS variables are still cool, 21 lines later)
span {
padding: 0;
line-height: 1;
font-size: var(--font-size);
position: absolute;
top: var(--top);
left: var(--left);
color: var(--color);
opacity: var(--opacity);
}
// Hmmmm. What glyphs do we want to use? I usually use cuss words, but I’ll tone it down.
const glyphs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Colors? Sure, we can have 5, 3, 11, 666… There’s a lot out there. Have fun with it! (I hate when people say that).
const colors = ['#f67809', '#faf7db', '#060606'];
// Choose the main thing to put the stuff in. (The Stuff was a good movie.)
const main = document.querySelector('body');
/*
All right now, this is where my brain fails and I feel dumber. We need to decide the number glyphs that get plopped and the font size on the square pixelage, so it's evenly filled when the window is big, small, short, wide and the font isn't HUGE on itty bitty windows or too small on the BIG ones.
*/
// How big is that window?
const width = window.innerWidth;
const height = window.innerHeight;
// We want to know how big the room is in square footage… er, window and square pixelage.
const squarePixelage = width * height;
const ratio = Math.floor(squarePixelage / 30000);
const fillRatio = ratio + 20;
// Give us a random number. We can tell it how high we want to get.
const rand = max => Math.floor(Math.random() * max);
// Give the background a random color. I hope it’s a good one.
main.style = `
--background-color: ${colors[rand(colors.length)]};
--opacity: ${rand(100) / 100 + 0.1}
`;
// The main event, plopping glyphs on the page.
function glyphIt(max) {
// We’re only gonna do this so many times.
for (let i = 0; i < max; i++) {
// Let’s get a random glyph
const glyph = glyphs[rand(glyphs.length)];
// OK, let's style that glyph with some random choices and make some HTML, a programming language.
const glyphElement = `
<span style="
--font-size: ${rand(fillRatio) + 5}rem;
--font-weight: ${300 + rand(700)};
--top: ${rand(height + 300) - 300}px;
--left: ${rand(width + 300) - 300}px;
--color: ${colors[rand(colors.length)]};
--opacity: ${rand(100) / 100 + 0.1}
">
${glyph}
</span>
`;
// Here we go, puttin’ it on the page or whatever.
main.insertAdjacentHTML('beforeend', glyphElement);
}
}
// Yup, we’re gonna do this. How many times?
// This is based on window size (see notes above).
// You could also replace the parameter with a number, multiple it, divide it, randomize it…. Neat thing about things is you can do many things or nothing.
glyphIt(fillRatio);
// Let’s do this! Ready‽ Oh, we already did.
// Thanks for stopping by! I hope you like this or at least I helped you exercise your eye muscles while you rolled them. I made this on my birthday, more fun than having a party.
Also see: Tab Triggers