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="c-mm">
<!--
Use checkbox-hack:
<input type="checkbox" id="anim1" name="slideshow" hidden />
<label class="c-mm__play" for="anim1"><span data-css-icon="play"><i></i></span></label>
-->
<details>
<summary class="c-mm__play"><span data-css-icon="play"><i></i></span></summary>
<span hidden></span>
</details>
<div class="c-mm__inner">
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:0;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/01.jpg" />
<figcaption data-caption="bottom left">Holiday Memories<div>Bornholm</div></figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-top;--index:1;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/02.jpg" />
<figcaption data-caption="bottom left">Rocky Beach</figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:2;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/03.jpg" />
<figcaption data-caption="top right">Opal Lake </figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-top;--index:3;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/04.jpg" />
<figcaption data-caption="bottom left">Melsted</figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:4;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/05.jpg" />
<figcaption data-caption="top right">Bigfoot<div>Stone Edition</div></figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-top;--index:5;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/06.jpg" />
<figcaption data-caption="top left">Hammer Lake<div>Opal Lake</div></figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:6;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/07.jpg" />
<figcaption data-caption="bottom left">Wild Garlic</figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-top;--index:7;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/08.jpg" />
<figcaption data-caption="top right">Wall Of Rock</figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:8;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/09.jpg" />
<figcaption data-caption="bottom left">Coastal Path<div>Gudhjem</div></figcaption>
</figure>
<figure class="c-mm__frame" style="--animn:kenburns-bottom-left;--index:9;">
<img class="c-mm__img" src="https://assets.stoumann.dk/img/movie/10.jpg" />
<figcaption data-caption="bottom left">Sunset At Bokul<div>Gudhjem</div></figcaption>
</figure>
</div>
</div>
<p>The <details>-tag is here used to play/pause the slideshow, using it's [open]-state (and :not([open])) to set two CSS Custom Properties, controlling the "animation-play-state" of both the overall slideshow and the animations of the individual slides. The images are from the most beautiful island in Denmark — the island of Bornholm, and are © me!</p>
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Castoro&family=Smythe&display=swap');
.c-mm {
--h: 9;
--w: 16;
--z: 100; /* z-index begin */
--animdur: 18000ms; /* 3 times the duration */
--animtf: ease-out;
--dist: clamp(0.75rem, 10vw, 1.5rem);
--slides: 20;
font-size: 1rem;
position: relative;
}
.c-mm::before {
content: '';
display: block;
padding-bottom: calc(var(--h) / var(--w) * 100%);
}
[data-caption] {
--b: var(--dist);
--l: var(--dist);
--r: initial;
--t: initial;
bottom: var(--b);
color: rgba(255, 255, 255, 0.9);
font-family: 'Bebas Neue', sans-serif;
font-size: clamp(1rem, 10vw, 4rem);
left: var(--l);
line-height: 1;
position: absolute;
right: var(--r);
top: var(--t);
}
[data-caption] div,
[data-filter] div {
font-family: 'Castoro', serif;
font-size: 50%;
}
[data-caption*="bottom"] {
--b: var(--dist);
--t: auto;
}
[data-caption*="left"] {
--l: var(--dist);
--r: auto;
}
[data-caption*="right"] {
--l: auto;
--r: var(--dist);
}
[data-caption*="top"] {
--b: auto;
--t: var(--dist);
}
.c-mm__frame {
--animps: paused;
--img-animps: paused;
--index: 0;
animation: autoplay var(--animdur) infinite;
animation-delay: calc((var(--index) * var(--animdur)) / 3);
animation-play-state: var(--animps);
box-sizing: border-box;
height: 100%;
margin: 0;
opacity: 0;
overflow: hidden;
padding: 0;
position: absolute;
top: 0;
width: 100%;
}
/* Alas, we cannot use var() in nth-selector :-(, so we need code for 3-20 items */
.c-mm__frame:nth-last-child(3):first-child,
.c-mm__frame:nth-last-child(3):first-child ~ .c-mm__frame {
animation-duration: var(--animdur);
}
.c-mm__frame:nth-last-child(4):first-child,
.c-mm__frame:nth-last-child(4):first-child ~ .c-mm__frame {
animation-duration: calc((4/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(5):first-child,
.c-mm__frame:nth-last-child(5):first-child ~ .c-mm__frame {
animation-duration: calc((5/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(6):first-child,
.c-mm__frame:nth-last-child(6):first-child ~ .c-mm__frame {
animation-duration: calc((6/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(7):first-child,
.c-mm__frame:nth-last-child(7):first-child ~ .c-mm__frame {
animation-duration: calc((7/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(8):first-child,
.c-mm__frame:nth-last-child(8):first-child ~ .c-mm__frame {
animation-duration: calc((8/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(9):first-child,
.c-mm__frame:nth-last-child(9):first-child ~ .c-mm__frame {
animation-duration: calc((9/3) * var(--animdur));
}
.c-mm__frame:nth-last-child(10):first-child,
.c-mm__frame:nth-last-child(10):first-child ~ .c-mm__frame {
animation-duration: calc((10/3) * var(--animdur));
}
.c-mm__img {
animation-direction: alternate;
animation-duration: calc(var(--animdur) / 1.5);
animation-fill-mode: both;
animation-iteration-count: infinite;
animation-name: var(--animn);
animation-play-state: var(--img-animps);
animation-timing-function: var(--animtf);
height: 100%;
object-fit: cover;
object-position: var(--x, 50%) var(--y, 50%);
position: absolute;
top: 0;
width: 100%;
will-change: transform;
}
.c-mm__inner {
height: 100%;
position: absolute;
top: 0;
width: 100%;
}
.c-mm__play {
--size: clamp(3rem, 10vw, 4rem);
align-items: center;
background: rgba(235,235,235,0.9);
box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1), 0px 2px 4px -1px rgba(0, 0, 0, 0.06);
border-radius: 50%;
display: flex;
height: var(--size);
justify-content: center;
position: absolute;
bottom: var(--dist);
right: var(--dist);
user-select: none;
width: var(--size);
z-index: calc(var(--z) + var(--slides) + 1);
}
.c-mm__play:hover {
background: rgba(255,255,255,0.9);
}
/* CHECKBOX-HACK STATE */
[name="slideshow"]:checked ~ .c-mm__inner .c-mm__frame {
--animps: running;
--img-animps: running;
}
[name="slideshow"]:not(:checked) ~ .c-mm__inner .c-mm__frame {
--animps: paused;
--img-animps: paused !important;
}
[name="slideshow"]:not(:checked) ~ .c-mm__inner .c-mm__frame:first-of-type {
opacity: 1;
}
[name="slideshow"]:checked + label [data-css-icon*="play"] i::after {
--cpa: polygon(40% 0%,0% 0%,0% 100%,40% 100%,40% 0%,60% 0%,100% 0%,100% 100%,60% 100%,60% 0%);
}
/* DETAILS STATE */
details[open] ~ .c-mm__inner .c-mm__frame {
--animps: running;
--img-animps: running;
}
details:not([open]) ~ .c-mm__inner .c-mm__frame {
--animps: paused;
--img-animps: paused !important;
}
details:not([open]) ~ .c-mm__inner .c-mm__frame:first-of-type {
opacity: 1;
}
details[open] summary [data-css-icon*="play"] i::after {
--cpa: polygon(40% 0%,0% 0%,0% 100%,40% 100%,40% 0%,60% 0%,100% 0%,100% 100%,60% 100%,60% 0%);
}
summary::marker { display: none; }
summary::-webkit-details-marker { display: none; }
@keyframes autoplay {
0.1% { --img-animps: running; opacity: 0; z-index: calc(var(--z) + var(--slides)) }
5% { opacity: 1 }
50% { opacity: 1 }
51% { --img-animps: paused }
100% { opacity: 0; z-index: var(--z) }
}
/* ----------------------------------------------
* Generated by Animista on 2020-11-25 9:5:10
* Licensed under FreeBSD License.
* See http://animista.net/license for more info.
* w: http://animista.net, t: @cssanimista
* ---------------------------------------------- */
@keyframes kenburns-top{0%{transform:scale(1) translateY(0);transform-origin:50% 16%}100%{transform:scale(1.25) translateY(-15px);transform-origin:top}}
@keyframes kenburns-top-right{0%{transform:scale(1) translate(0,0);transform-origin:84% 16%}100%{transform:scale(1.25) translate(20px,-15px);transform-origin:right top}}
@keyframes kenburns-right{0%{transform:scale(1) translate(0,0);transform-origin:84% 50%}100%{transform:scale(1.25) translateX(20px);transform-origin:right}}
@keyframes kenburns-bottom-right{0%{transform:scale(1) translate(0,0);transform-origin:84% 84%}100%{transform:scale(1.25) translate(20px,15px);transform-origin:right bottom}}
@keyframes kenburns-bottom{0%{transform:scale(1) translateY(0);transform-origin:50% 84%}100%{transform:scale(1.25) translateY(15px);transform-origin:bottom}}
@keyframes kenburns-bottom-left{0%{transform:scale(1) translate(0,0);transform-origin:16% 84%}100%{transform:scale(1.25) translate(-20px,15px);transform-origin:left bottom}}
@keyframes kenburns-left{0%{transform:scale(1) translate(0,0);transform-origin:16% 50%}100%{transform:scale(1.25) translate(-20px,15px);transform-origin:left}}
@keyframes kenburns-top-left{0%{transform:scale(1) translate(0,0);transform-origin:16% 16%}100%{transform:scale(1.25) translate(-20px,-15px);transform-origin:top left}}
/* FROM CSS-ICONS-PEN, slightly modified */
[data-css-icon] {
--icon-size: 1.5rem;
--size: 3.75rem;
--bdrs: 50%;
--c: currentcolor;
align-items: center;
cursor: pointer;
display: flex;
justify-content: space-between;
}
[data-css-icon] i {
align-items: center;
border-radius: var(--bdrs);
box-sizing: content-box;
display: inline-flex;
height: var(--size);
justify-content: center;
position: relative;
width: var(--size);
}
[data-css-icon] i::after {
--cpa: none;
--h: var(--icon-size);
--w: var(--icon-size);
background-color: var(--bgcl);
clip-path: var(--cpa);
content: "";
display: inline-block;
height: var(--h);
margin: 0;
width: var(--w);
}
[data-css-icon*="play"] i::after {
--bgcl: var(--c);
--cpa: polygon(16% 0%,15% 100%,100% 50%);
}
/* SAFARI HACK */
@media not all and (min-resolution:.001dpcm) {
@supports (-webkit-appearance:none) {
summary [data-css-icon] i {
right: -2px;
top: 2px;
}
}
}
body { font-family: system-ui, sans-serif; margin: 0 auto; max-width: 54rem; padding: 1rem }
p { color: silver }
/* JavaScript Not Required! */
Also see: Tab Triggers