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.
<header>
<h1>Demo of line using height units for paragraph margins</h1>
</header>
<main>
<section class="demo paragraphs-demo">
<h2>Paragraphs</h2>
<div class="interface">
<label class="margins" for="paragraphs-margins">margin-block<span>:</span>
<select name="paragraphs-margins" id="paragraphs-margins">
<option value="one-line-height">1lh<span>;</span></option>
<option value="one-em">1em<span>;</span></option>
<option value="zero">0<span>;</span></option>
</select>
</label>
<label class="margins" for="margin-trim">margin-trim<span>:</span>
<select name="margin-trim" id="margin-trim">
<option value="margin-trim-none">none<span>;</span></option>
<option value="margin-trim-block">block<span>;</span></option>
<option value="margin-trim-block-start">block-start<span>;</span></option>
<option value="margin-trim-block-end">block-end<span>;</span></option>
</select>
</label>
<label for="font-paragraphs">Font:
<select name="font-options" id="font--headline-image">
<option value="old-style">Old Style</option>
<option value="system-ui">System UI</option>
<option value="transitional">Transitional</option>
<option value="humanist">Humanist</option>
<option value="geometric-humanist">Geometric Humanist</option>
<option value="classical-humanist">Classical Humanist</option>
<option value="neo-grotesque">Neo-Grotesque</option>
<option value="monospace-slab-serif">Monospace Slab Serif</option>
<option value="monospace-code">Monospace Code</option>
<option value="industrial">Industrial</option>
<option value="rounded-sans">Rounded Sans</option>
<option value="slab-serif">Slab Serif</option>
<option value="antique">Antique</option>
<option value="didone">Didone</option>
<option value="handwritten">Handwritten</option>
</select>
</label>
<label for="margin-guides" class="margins">Show margins:
<input type="checkbox" switch id="margin-guides">
</label>
<label for="line-grid" class="line-grid">Show line grid:
<input type="checkbox" switch id="line-grid">
</label>
<aside class="margin-trim-support"><p>(This browser does not support <code>margin-trim</code>. Try this demo in Safari, or another <a href="https://caniuse.com/mdn-css_properties_margin-trim" target="_blank">browser that does</a>.)</p></aside>
</div>
<article class="paragraphs">
<div> <!--just-for-the-guides-->
<p>Lorem ipsum dolor sit amet, similique moderatius sea ex. Te assum principes mea. Illum suavitate vis no, cu utroque nonumes accusamus vix. Impetus officiis vim et, eu discere delicata mel. His te malis tantas. An probo omnium cotidieque sed, nec dicat blandit et, mucius feugait vivendum per id.</p>
<p>Ut eum posse alterum, commodo instructior ne nec. Vero viris ut vel, id salutatus constituam ius. Suscipit persecuti te ius, id quem ridens eam, quo te fugit torquatos elaboraret. Mei ex doctus recteque iudicabit. Blandit deserunt cu vis, his et atqui homero. Erat dissentiet voluptatibus ex vis, et omnis honestatis pro.</p>
<p>Eu quando inermis usu, qui magna illum in. Qui idque primis id. Cu luptatum perfecto ius, mel ne soluta offendit, quo viris fastidii in. An affert utamur theophrastus pro. Id impedit molestie accusata vel, te vix ridens gubergren liberavisse.</p>
<p>Mea te theophrastus contentiones. At vix populo propriae. Eros volumus splendide ex vis. Modus incorrupte ut his. Ex duo modus mazim eirmod. Quo detracto complectitur an, ad qui postea dissentiunt.</p>
<p>Sea et debitis torquatos scriptorem. Ut euismod feugait convenire vix, vim quem consetetur intellegebat te. Mel an noster persius vocibus, no vix rebum omittantur complectitur, cu est quot doming scriptorem. Sit ne malis lobortis argumentum, per et illum ridens adipiscing, eum at sale necessitatibus. Nusquam aliquando accommodare in cum, sed simul timeam ne.</p>
<figure class="grid-lines">
<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>
</figure>
</div>
</article>
</section>
</main>
/*-------------------------------------------*/
/* Options */
/*-------------------------------------------*/
/* Margin block */
section:has(option[value="zero"]:checked) article p {
margin-block: 0;
}
section:has(option[value="one-em"]:checked) article p {
margin-block: 1em;
}
section:has(option[value="one-line-height"]:checked) article p {
margin-block: 1lh;
}
/* Margin trim */
section:has(option[value="margin-trim-none"]:checked) article div {
margin-trim: none;
}
section:has(option[value="margin-trim-block"]:checked) article div {
margin-trim: block;
}
section:has(option[value="margin-trim-block-start"]:checked) article div {
margin-trim: block-start;
}
section:has(option[value="margin-trim-block-end"]:checked) article div {
margin-trim: block-end;
}
/* Support note about margin-trim */
.margin-trim-support {
display: none;
font-size: 85%;
line-height: 1.4;
background: light-dark(rgb(255, 0, 0, 0.2), rgb(140, 63, 95));
margin-block: 1lh;
padding: 1px 1lh;
a {
color: light-dark(black, #f5abca);
}
}
section:has(option[value="margin-trim-block"]:checked) {
@supports not (margin-trim: block) {
.margin-trim-support {
display: block;
}
}
}
/*-------------------------------------------*/
/* Paragraphs and Guides */
/*-------------------------------------------*/
.paragraphs {
p {
font-size: 1.2rem;
line-height: 1.3;
}
}
.paragraphs div {
border: 1px solid canvas;
}
body:has(input[id="margin-guides"]:checked) {
.paragraphs {
background-color: light-dark(lemonchiffon, midnightblue);
div {
background-color: light-dark(rgb(0, 232, 232, 0.3),
color(display-p3 0 0.431 0.435));
}
p {
background-color: canvas;
}
}
}
/*-------------------------------------------*/
/* Line Grid */
/*-------------------------------------------*/
.grid-lines {
display: none;
}
body:has(input[id="line-grid"]:checked) {
.grid-lines {
width: 100%;
height: calc(100% + 1px);
margin: 0;
padding: 0;
display: block;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
hr {
margin: 0;
padding: 0;
width: 100%;
height: 1lh;
border: 0;
border-block: 0.5px solid light-dark(#00e8e8,
color(display-p3 0 0.634 0.64));
}
hr:nth-child(1) {
border-block-start-width: 1px;
}
}
}
/*-------------------------------------------*/
/* Overall page and UI */
/*-------------------------------------------*/
*, *::before, *::after { box-sizing: border-box; }
:root {
color-scheme: light dark;
--code-font: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
--code-color: rebeccapurple;
}
body {
margin: 4rem;
font-family: ui-rounded, system-ui, sans-serif;
background: light-dark(#f0ebd4, color(display-p3 0.181 0.235 0.059));
}
header {
text-align: center;
color: light-dark(green, hotpink);
code { color: green; font-family: inherit; }
h1 {
font-size: 3.2rem;
margin: 0;
font-weight: 100;
text-wrap: balance;
}
}
code {
color: var(--code-color);
font-family: var(--code-font);
}
main {
display: grid;
gap: 4rem;
margin-block-start: 3rem;
margin-inline: auto;
max-width: 1250px;
}
main, button {
font-family: var(--font-family);
}
section.demo {
display: grid;
grid-template-columns: 32ch 1fr;
grid-template-rows: max-content 1fr;
grid-template-areas: "header demo"
"interface demo";
gap: 2rem 1rem;
background: light-dark(#faf6e3, #c8bf93);
align-items: start;
> h2 {
grid-area: header;
font-size: 1.8rem;
font-weight: 100;
color: #6e5b45;
margin: 0;
padding: 2rem 0 0 2rem;
}
.interface {
grid-area: interface;
padding: 0 0 2rem 2rem;
/* should be padding-inline-start: 2rem; for narrow screens*/
font-family: var(--code-font);
label, select { color: var(--code-color); }
label { display: block; margin-block-end: 0.5lh;}
span { color: black; }
.guides {
display: flex;
align-items: center;
gap: 0.5lh;
accent-color: var(--code-color);
}
}
article div {
position: relative;
}
article {
grid-area: demo;
background: canvas;
color: textColor;
padding: 2lh;
width: 100%;
align-self: stretch;
align-items: center;
font-size: 1.2rem;
line-height: 1.3;
}
}
@media (max-width: 800px) {
body {
margin: 1.5rem;
}
header {
h1 {
font-size: 1.8rem;
}
}
main {
margin-block-start: 1.5rem;
}
section.demo {
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-template-areas: "header"
"interface"
"demo";
.interface {
padding: 0 0 0 2rem;
}
article {
padding: 1lh;
}
}
}
select {
appearance: none;
width: auto;
margin: 0;
padding: 0.25em 0.5em;
font-family: inherit;
font-size: inherit;
line-height: inherit;
cursor: pointer;
background-color: rgb(255, 255, 255, .5);
background-image: linear-gradient(to top, rgb(0, 0, 0, 0.03), rgb(255, 255, 255, 0) 50%);
border: 1px solid #ebe7e2;
border-radius: 0.25em
}
/*-------------------------------------------*/
/* Font Options */
/*-------------------------------------------*/
/* Thanks modernfontstacks.com for the font stacks! */
section article {
font-family: var(--font-family);
}
section:has(option[value="system-ui"]:checked) {
--font-family: system-ui, sans-serif;
}
section:has(option[value="transitional"]:checked) {
--font-family: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
}
section:has(option[value="system-ui"]:checked) {
--font-family: system-ui, sans-serif;
}
section:has(option[value="system-ui"]:checked) {
--font-family: system-ui, sans-serif;
}
section:has(option[value="transitional"]:checked) {
--font-family: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
}
section:has(option[value="old-style"]:checked) {
--font-family: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;
}
section:has(option[value="humanist"]:checked) {
--font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
}
section:has(option[value="geometric-humanist"]:checked) {
--font-family: Avenir, Montserrat, Corbel, 'URW Gothic', source-sans-pro, sans-serif;
}
section:has(option[value="classical-humanist"]:checked) {
--font-family: Optima, Candara, 'Noto Sans', source-sans-pro, sans-serif;
}
section:has(option[value="neo-grotesque"]:checked) {
--font-family: Inter, Roboto, 'Helvetica Neue', 'Arial Nova', 'Nimbus Sans', Arial, sans-serif;
}
section:has(option[value="monospace-slab-serif"]:checked) {
--font-family: 'Nimbus Mono PS', 'Courier New', monospace;
}
section:has(option[value="monospace-code"]:checked) {
--font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
}
section:has(option[value="industrial"]:checked) {
--font-family: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
}
section:has(option[value="rounded-sans"]:checked) {
--font-family: ui-rounded, 'Hiragino Maru Gothic ProN', Quicksand, Comfortaa, Manjari, 'Arial Rounded MT', 'Arial Rounded MT Bold', Calibri, source-sans-pro, sans-serif;
}
section:has(option[value="slab-serif"]:checked) {
--font-family: Rockwell, 'Rockwell Nova', 'Roboto Slab', 'DejaVu Serif', 'Sitka Small', serif;
}
section:has(option[value="antique"]:checked) {
--font-family: Superclarendon, 'Bookman Old Style', 'URW Bookman', 'URW Bookman L', 'Georgia Pro', Georgia, serif;
--font-family: Superclarendon, monospace;
}
section:has(option[value="didone"]:checked) {
--font-family: Didot, 'Bodoni MT', 'Noto Serif Display', 'URW Palladio L', P052, Sylfaen, serif;
}
section:has(option[value="handwritten"]:checked) {
--font-family: 'Segoe Print', 'Bradley Hand', Chilanka, TSCu_Comic, casual, cursive;
}
Also see: Tab Triggers