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.
<h1>
I ❤ CSS
</h1>
<p data-bg="oddbird">
please design responsibly…
</p>
<p style="--bg-hue: var(--mia-hue)">
A pen by Miriam Suzanne
</p>
/* Generate a default background based on any hue */
body {
--bg-hue: 270;
}
/* Override the default settings to customize your result */
h1 {
--bg-hue: 180;
--bg-tint-angle: to bottom left;
--bg-tint-start: 70%;
--bg-shade-angle: 80deg;
}
/* Create defaults that can be re-used via html */
[data-bg~='oddbird'] {
--bg-color: hsl(195, 52%, 31%);
--bg-tint: hsla(24, 100%, 62%, 0.75);
--bg-shade: hsla(330, 100%, 45%, 0.75);
}
/* We could also provide preset values to choose from */
[style*='--bg-'] {
--mia-hue: 330;
--mia-color: hsl(330, 100%, 29%);
}
/*
The mixin logic
---------------
- I've exposed more variables than you would need to.
Each additional variable provides another "argument" to the API.
For patterns that require less customization, use fewer variables.
- Defining it on the * selector makes this globally available,
but it could also be scoped to any selector you want.
Scoping functions/mixins to the DOM is a feature that only CSS can provide.
*/
* {
/* Setting a valid hue (any unitless number) will auto-set all the other values */
--bg-hue: unset;
/* Adjust the base saturation and lightness as desired */
--bg-saturation: 50%;
--bg-lightness: 40%;
/* set angles for the tint and shade gradients */
--bg-tint-angle: -20deg;
--bg-shade-angle: -110deg;
/* set amounts for default tint & shade */
--bg-tint-amount: 20%;
--bg-shade-amount: 20%;
/* set indiviidual hues for the tint and shade */
/* defaults are set by higher-level arguments…
which alows for both simpler & more customized uses*/
--bg-tint-hue: var(--bg-hue);
--bg-shade-hue: var(--bg-hue);
/* set the gradient positions all at once */
--bg-gradient-stops: 30%;
/* override tint/shade gradients directly */
--bg-tint-start: var(--bg-gradient-stops);
--bg-tint-end: var(--bg-tint-start);
--bg-shade-start: var(--bg-gradient-stops);
--bg-shade-end: var(--bg-shade-start);
/* override tint/shade saturation & lightness directly */
--bg-tint-saturation: var(--bg-saturation);
--bg-tint-lightness: calc(var(--bg-lightness) + var(--bg-tint-amount));
--bg-shade-saturation: var(--bg-saturation);
--bg-shade-lightness: calc(var(--bg-lightness) - var(--bg-shade-amount));
/* or override any individual color directly */
--bg-color: hsl(var(--bg-hue), var(--bg-saturation), var(--bg-lightness));
--bg-tint: hsla(var(--bg-tint-hue), var(--bg-tint-saturation), var(--bg-tint-lightness), 0.25);
--bg-shade: hsla(var(--bg-shade-hue), var(--bg-shade-saturation), var(--bg-shade-lightness), 0.25);
/* this is the internal logic that creates your angled tint/shade background */
--bg-image:
linear-gradient(
var(--bg-tint-angle),
var(--bg-tint) var(--bg-tint-start),
transparent var(--bg-tint-end)
),
linear-gradient(
var(--bg-shade-angle),
var(--bg-shade) var(--bg-shade-start),
transparent var(--bg-shade-end)
)
;
/* Creating a final "output" variable acts like a function return */
--bg: var(--bg-image) var(--bg-color);
/* Applying that value to a property creates a mixin */
/* Since the initial return is invalid, nothing happens unless we set a --bg-hue */
background: var(--bg);
}
/* Just the layout */
* { box-sizing: border-box; }
body {
display: grid;
align-content: center;
justify-content: center;
grid-auto-rows: minmax(auto, 1fr);
grid-auto-columns: minmax(auto, 1fr);
grid-gap: 1em;
min-height: 100vh;
padding: calc(2em + 10vmin);
}
h1, p {
display: grid;
align-content: center;
justify-content: center;
border: 2px solid white;
margin: 0;
padding: 1em;
}
p {
color: white;
}
Also see: Tab Triggers