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.
- var data = [
- {
- slist: ['329, 100%, 70%', '337, 99%, 58%'],
- icon: 'π',
- title: 'gingerbread',
- ptext: 'Cake muffin donut chocolate cake jelly sesame wafer tart pie muffin.'
- },
- {
- slist: ['48, 99%, 58%', '33, 94%, 55%'],
- icon: 'π',
- title: 'brownie',
- ptext: 'Cake cookie lemon muffin plum. Orange topping macaroon chocolate.'
- },
- {
- slist: ['272, 46%, 54%', '273, 78%, 48%'],
- icon: 'π',
- title: 'ice cream',
- ptext: 'Cake muffin donut chocolate cake jelly sesame wafer tart pie muffin.'
- },
- {
- slist: ['174, 84%, 34%', '193, 99%, 27%'],
- icon: 'π',
- title: 'lava cake',
- ptext: 'Cake cookie lemon muffin plum. Orange topping macaroon chocolate.'
- }
- ];
- var n = data.length;
- var comp = ['hue', 'sat', 'lum'];
- for(var i = 0; i < n; i++)
- let m = data[i].slist.length;
- let s = [];
- for(var j = 0; j < m; j++)
- var c = data[i].slist[j].split(', ');
- for(var k = 0; k < 3; k++)
- s.push(`--${comp[k]}${j}: ${c[k]}`)
article(data-icon=`${data[i].icon}` style=`${s.join('; ')}; --idx: ${i}`)
h3 option
h4 #{data[i].title}
p #{data[i].ptext}
@import 'compass/css3';
$lum0: 98%;
$lum1: 83%;
$sat: 9%;
$lin-h: 1.25;
$hd4-fs: 2.25rem;
// WIDE CASE
// rows
$row-1-wide: $hd4-fs*$lin-h;
$row-2-wide: 3.75rem;
$row-3-wide: 0;
// columns
$col-a-wide: 11.5rem; // option numbering
$col-b-wide: 14rem; // heading & text
$col-c-wide: 5rem; // icon
$col-d-wide: .375rem; // separator
$col-1-wide: calc(var(--q)*#{$col-a-wide} + var(--p)*#{$col-b-wide});
$col-2-wide: calc(var(--q)*#{$col-c-wide} + var(--p)*#{$col-d-wide});
$col-3-wide: calc(var(--q)*#{$col-d-wide} + var(--p)*#{$col-c-wide});
$col-4-wide: calc(var(--q)*#{$col-b-wide} + var(--p)*#{$col-a-wide});
$art-g-wide: 1.5rem;
$art-b-wide: .1875rem;
$art-p-wide: 2.25rem;
$art-w-wide: $col-a-wide + $col-b-wide + $col-c-wide + $col-d-wide +
4*$art-g-wide + 2*$art-b-wide;
$art-h-wide: $row-1-wide + 3*$lin-h*1rem +
2*$art-p-wide + 2*$art-b-wide;
$art-r-wide: 9px;
$art-gb-wide: 1rem;
$art-gr-wide: (pow(.5*$art-h-wide, 2) + pow($art-gb-wide, 2))/$art-gb-wide*1rem;
$art-gd-wide: $art-gr-wide - $col-a-wide - $art-b-wide;
$art-gx-wide: calc(var(--p)*100% - var(--s)*#{$art-gd-wide});
$hd3-mv-wide: -($art-p-wide + $art-b-wide);
$hd3-mr-wide: calc(var(--p)*#{-$art-b-wide});
$hd3-ml-wide: calc(var(--q)*#{-$art-b-wide});
$hd3-pv-wide: $art-p-wide + $art-b-wide;
$hd3-fs-wide: .25*($row-1-wide + 3*$lin-h*1rem);
$hd3-lh-wide: 1;
$num-fs-wide: 3em;
$ico-fs-wide: $col-c-wide/$lin-h;
$art-gf: $art-gb-wide/$art-h-wide;
// NORM CASE
$row-1-norm: 15vw;
$row-2-norm: $hd4-fs*$lin-h;
$col-2-norm: $row-2-norm;
$col-1-norm: calc(100% - #{$col-2-norm});
$art-p-norm: 2vw;
$art-gb-norm: $art-gf*100vw;
$art-gr-norm: (pow(.5*100vw, 2) + pow($art-gb-norm, 2))/$art-gb-norm*1vw;
$art-gd-norm: $art-gr-norm - $row-1-norm - $art-p-norm;
$art-gy-norm: -$art-gd-norm;
$hd3-m-norm: -$art-p-norm;
$hd3-lh-norm: 1.75;
$hd3-fs-norm: ($row-1-norm - .375*$art-gb-norm)/$hd3-lh-norm;
$num-fs-norm: 1em;
$ico-fs-norm: $row-2-norm/$lin-h;
// UNIF CASE
$row-1: calc(var(--i)*#{$row-1-wide} + var(--j)*#{$row-1-norm});
$row-2: calc(var(--i)*#{$row-2-wide} + var(--j)*#{$row-2-norm});
$row-3: calc(var(--j)*3.75rem);
$col-1: calc(var(--i)*#{$col-1-wide} + var(--j)*#{$col-1-norm});
$col-2: calc(var(--i)*#{$col-2-wide} + var(--j)*#{$col-2-norm});
$col-3: calc(var(--i)*#{$col-3-wide});
$col-4: calc(var(--i)*#{$col-4-wide});
$art-g: calc(var(--i)*#{$art-g-wide});
$art-b: calc(var(--i)*#{$art-b-wide});
$art-pv: calc(var(--i)*#{$art-p-wide} + var(--j)*#{$art-p-norm});
$art-pr: calc(var(--i)*var(--q)*#{$art-g-wide} + var(--j)*#{$art-p-norm});
$art-pl: calc(var(--i)*var(--p)*#{$art-g-wide} + var(--j)*#{$art-p-norm});
$art-r: calc(var(--i)*#{$art-r-wide});
$art-gr: calc(var(--i)*#{$art-gr-wide} + var(--j)*#{$art-gr-norm});
$art-gd: calc(var(--i)*#{$art-gd-wide} + var(--j)*#{$art-gd-norm});
$art-gx: calc(var(--i)*#{$art-gx-wide} + var(--j)*50%);
$art-gy: calc(var(--i)*50% + var(--j)*#{$art-gy-norm});
$hd3-mt: calc(var(--i)*#{$hd3-mv-wide} + var(--j)*#{$hd3-m-norm});
$hd3-mr: calc(var(--i)*#{$hd3-mr-wide} + var(--j)*#{$hd3-m-norm});
$hd3-mb: calc(var(--i)*#{$hd3-mv-wide});
$hd3-ml: calc(var(--i)*#{$hd3-ml-wide} + var(--j)*#{$hd3-m-norm});
$hd3-pv: calc(var(--i)*#{$hd3-pv-wide});
$hd3-fs: calc(var(--i)*#{$hd3-fs-wide} + var(--j)*#{$hd3-fs-norm});
$hd3-lh: calc(var(--i)*#{$hd3-lh-wide} + var(--j)*#{$hd3-lh-norm});
$num-fs: calc(var(--i)*#{$num-fs-wide} + var(--j)*#{$num-fs-norm});
$ico-fs: calc(var(--i)*#{$ico-fs-wide} + var(--j)*#{$ico-fs-norm});
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
--i: var(--wide, 1);
--j: calc(1 - var(--i));
background: #818286;
$c: rgba(#fff, .8);
background:
linear-gradient($c, $c),
url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2017/kreator_rockharz_july_2018.jpg)
50%/ cover;
font: 400 1em/ #{$lin-h}
koho, trebuchet ms, verdana, century gothic, arial, sans-serif;
@media (max-width: $art-w-wide) { --wide: 0 }
@media (max-width: 250px) { font-size: .75em }
}
article {
--p: var(--parity, 0);
--q: calc(1 - var(--p));
--s: calc(1 - 2*var(--p));
display: grid;
grid-template:
#{$row-1} #{$row-2} #{$row-3}/
#{$col-1} #{$col-2} #{$col-3} #{$col-4};
grid-gap: 0 $art-g;
margin: .5em auto;
border: solid $art-b transparent;
padding: $art-pv $art-pr $art-pv $art-pl;
max-width: $art-w-wide;
border-radius: $art-r;
background:
Linear-gradient(calc(var(--s)*90deg),
HSL(var(--hue0),
calc(var(--p)*var(--sat0) + var(--q)*#{$sat}),
calc(var(--p)*var(--lum0) + var(--q)*#{$lum0})) calc(var(--i)*#{$col-a-wide}),
HSL(var(--hue1),
calc(var(--p)*var(--sat1) + var(--q)*#{$sat}),
calc(var(--p)*var(--lum1) + var(--q)*#{$lum1}))) padding-box,
Linear-gradient(calc(var(--s)*90deg),
HSL(var(--hue1),
calc(var(--p)*var(--sat1) + var(--q)*#{$sat}),
calc(var(--p)*var(--lum1) + var(--q)*#{$lum1})) $col-a-wide + $art-b-wide,
HSL(var(--hue0),
calc(var(--p)*var(--sat0) + var(--q)*#{$sat}),
calc(var(--p)*var(--lum0) + var(--q)*#{$lum0}))) border-box;
color: HSL(var(--hue1),
calc(var(--q)*var(--sat1) + var(--p)*#{$sat}),
calc(var(--q)*var(--lum1) + var(--p)*#{$lum0}));
counter-increment: idx;
&:before {
grid-column:
/* starts on 3rd col for odd items, 2nd for even in wide case */
calc((3*var(--q) + 2*var(--p)))/
/* always spans just 1 col */
span 1;
grid-row:
/* starts on 1st row in wide case */
1/
/* spans all 3 rows in wide case */
span 3;
width: calc(var(--i)*#{$col-d-wide});
border-radius: $col-d-wide;
box-shadow: inset 2px 0 5px rgba(#000, .35),
inset -1px 0 3px rgba(#fff, .25),
1px 0 1px rgba(#fff, .5);
background: HSL(var(--hue1), var(--sat1), var(--lum1));
content: ''
}
&:after {
grid-column:
/* starts on 2nd col for odd items, 3rd for even in wide case */
calc(var(--i)*(2*var(--q) + 3*var(--p)) + 2*var(--j))/
/* always spans just 1 col */
span 1;
grid-row:
/* starts on 1st row in wide case, 2nd for norm */
calc(var(--i) + 2*var(--j))/
/* spans all 3 rows in wide case, just 1 in narrow case */
span calc(3*var(--i) + var(--j));
place-self: center;
font-size: $ico-fs;
filter: Grayscale(var(--p))
Brightness(calc(var(--q) + 1.25*var(--p)));
content: attr(data-icon)
}
&:nth-child(2n) { --parity: 1 }
}
h3 {
display: grid;
grid-template:
repeat(calc(1 + 3*var(--i)), 1fr)/
repeat(calc(1 + 2*var(--j)), 1fr);
place-items: center;
grid-column:
/* starts on 1st col for odd items, 4th for even in wide case */
calc(var(--i)*(var(--q) + 4*var(--p)) + var(--j))/
/* spans just 1 col in wide case, all non-zero ones in normal */
span calc(var(--i) + 2*var(--j));
grid-row:
/* always starts on 1st row */
1/
/* spans all 3 rows in wide case, just 1 in narrow case */
span calc(3*var(--i) + var(--j));
margin: $hd3-mt $hd3-mr $hd3-mb $hd3-ml;
padding: $hd3-pv 0;
border-radius: inherit;
background:
//linear-gradient(pink, pink) content-box,
Radial-gradient(circle at $art-gx $art-gy,
HSL(var(--hue0),
calc(var(--q)*var(--sat0) + var(--p)*#{$sat}),
calc(var(--q)*var(--lum1) + var(--p)*#{$lum0})) $art-gd,
HSL(var(--hue1),
calc(var(--q)*var(--sat1) + var(--p)*#{$sat}),
calc(var(--q)*var(--lum1) + var(--p)*#{$lum1})) $art-gr);
color: HSL(var(--hue1), var(--sat1), calc(var(--p)*var(--lum1) + var(--q)*#{$lum0}));
font-size: $hd3-fs;
font-weight: 600;
line-height: $hd3-lh;
text-align: center;
text-transform: uppercase;
clip-path: circle($art-gr at $art-gx $art-gy);
&:before {
grid-row: 1/ span calc(1 + var(--j));
font-size: $num-fs;
content: counter(idx, decimal-leading-zero)
}
}
h4 {
grid-column:
/* starts on 4th col for odd items, 1st for even in wide case */
calc(var(--i)*(4*var(--q) + var(--p)) + var(--j))/
/* always spans 1 col */
span 1;
grid-row:
calc(var(--i) + 2*var(--j))/
/* always spans 1 row */
span 1;
//background: rgba(red, .2);
font-size: $hd4-fs;
font-weight: 500;
text-transform: capitalize;
}
p {
grid-column:
/* starts on 4th col for odd items, 1st for even in wide case */
calc(var(--i)*(4*var(--q) + var(--p)) + var(--j))/
/* spans 1 col in the wide case and 2 in the norm case */
span calc(var(--i) + 2*var(--j));
grid-row:
calc(2*var(--i) + 3*var(--j))/
/* always spans 1 row */
span 1;
//background: rgba(purple, .2);
}
Also see: Tab Triggers