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.
<input type="checkbox" id="debug" />
<ul class="cards" tabindex="0">
<li class="snapped">
<div class="title">Volume 1</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Front-1024x1024.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">A Thousand Clouds</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--A-Thousand-Clouds-Front-Cover-1024x1024.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Odd World</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Odd-World-EP-SMALL-1024x1024.png" width="1200" height="1200" />
</li>
<li>
<div class="title">Forest Blue</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Forest-Blue-Pre-LR-1024x1024.png" width="1200" height="1200" />
</li>
<li>
<div class="title">Mountain of Memory</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--MOM-Remixes-1024x1024.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Alone Together</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--ALONE-TOGETHER-remix-V71-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Nature Therapy</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Nature-Therapy-Pre-LR-550x550.png" width="1200" height="1200" />
</li>
<li>
<div class="title">Deep Dive</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Deep-Dive-Ambient-Edits-V8-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Alpine</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Alpine-Koresma-x-Aroth-Artwork-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Out Of The Dark</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Out-Of-the-Dark-Cover-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Single Blue</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--2020-06-07-Marley-Carroll-Single-Blue-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Deep Dive</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Deep-Dive-EP-Cover-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Blackrose</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Blackrose-Cover-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Imagine Gold</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--FW-Imagine-Gold-Remixes2-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">We Are</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--We-Are-COVER-MAIN-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Bath House</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Bath-House-Flat-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Pronoia</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Pronoia-JPG-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Cracking Stories</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Lapa9Theory-Cracking-Stores-no-Loci-logo-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Emancipator</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--EMANCIPATOR_MOM_AlbumCover-2000px-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Here We All Are</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--MURGE-ep-cvr-3000x3000-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Laybrinth</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--Emancipator_Laybrinth-ART-01-4000x4000-at-300dpi-550x550.jpg" width="1200" height="1200" />
</li>
<li>
<div class="title">Climbing</div>
<img draggable="false" src="https://assets.codepen.io/89905/coverflow--cover-550x550.jpg" width="1200" height="1200" />
</li>
</ul>
<footer>
<p>Looking for more Scroll-Driven Animations Info + Demos? I’ve put together <a href="https://scroll-driven-animations.style/" target="_top">scroll-driven-animations.style</a> especially for you!</p>
</footer>
<div class="warning">
<p>⚠️ Your browser does not support CSS Scroll-Linked Animations with <code>view-timeline</code>. Please try Chrome Canary 115+.</p>
</div>
@layer base, components;
@supports (view-timeline: --works) {
/* Hide warning when native view-timeline support detected */
.warning {
display: none;
}
/* Animation bumps up the z-index, to make sure it’s on top */
@keyframes adjust-z-index {
0% {
z-index: 1;
}
50% {
z-index: 100; /* When at the center, be on top */
}
100% {
z-index: 1;
}
}
/* Animation that rotates the cover */
@keyframes rotate-cover {
0% {
transform: translateX(-100%) rotateY(-45deg);
}
35% {
transform: translateX(0) rotateY(-45deg);
}
50% {
transform: rotateY(0deg) translateZ(1em) scale(1.5);
}
65% {
transform: translateX(0) rotateY(45deg);
}
100% {
transform: translateX(100%) rotateY(45deg);
}
}
.cards li {
/* Track this element as it intersects the scrollport */
view-timeline-name: --li-in-and-out-of-view;
view-timeline-axis: inline;
/* Link an animation to the established view-timeline and have it run during the contain phase */
animation: linear adjust-z-index both;
animation-duration: auto;
animation-timeline: --li-in-and-out-of-view;
animation-range: contain 0% contain 100%; /* For Canary */
/* Make the 3D stuff work… */
perspective: 40em;
position: relative;
z-index: 1;
will-change: z-index;
user-select: none;
& > .title {
transition: opacity .3s ease, transform .3s ease;
opacity: 0;
transform: translateY(5px);
font-size: 1.5rem;
font-weight: bold;
text-align: center;
position: relative;
top: -35%;
}
&.snapped > .title {
opacity: 1;
transform: translateY(0px);
}
}
.cards li > img {
/* Link an animation to the established view-timeline (of the parent li) and have it run during the contain phase */
animation: linear rotate-cover both;
animation-duration: auto;
animation-timeline: --li-in-and-out-of-view;
animation-range: contain 0% contain 100%;
/* Prevent FOUC */
transform: translateX(-100%) rotateY(-45deg);
will-change: transform;
}
}
@layer base {
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
:root {
--cover-size: 15rem;
}
@media (max-width: 800px) {
:root {
--cover-size: 9rem;
}
}
@media (max-width: 500px) {
:root {
--cover-size: 6rem;
}
}
html, body {
height: 100%;
width: 100%;
color: #ccc;
background: #111;
text-align: center;
}
body {
font-family: sans-serif;
display: flex;
flex-direction: column;
gap: 1em;
padding: 1em;
}
@supports (place-content: safe center) {
body {
place-content: safe center;
}
}
a {
color: papayawhip;
}
footer {
font-style: italic;
margin-top: 1em;
}
.cards {
list-style: none;
overflow-x: scroll;
width: 100%;
white-space: nowrap;
outline: 1px solid #333;
background: rgba(0 0 0 / 0.5);
}
.cards:focus {
outline-color: #666;
}
/* only enable snapping when not dragging round*/
.cards:not(.active) {
scroll-snap-type: x mandatory;
}
.cards li {
display: inline-block;
width: var(--cover-size);
height: var(--cover-size);
scroll-snap-align: center;
}
.cards li img {
dislay: block;
width: var(--cover-size);
height: var(--cover-size);
-webkit-box-reflect: below 0.5em
linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.25));
}
.cards {
min-height: calc(var(--cover-size) * 2.5);
max-width: calc(var(--cover-size) * 6);
margin: 0 auto;
padding: calc(var(--cover-size) / 3 * 2) 0;
}
.cards li:first-of-type {
margin-left: calc(50% - var(--cover-size) / 2);
}
.cards li:last-of-type {
margin-right: calc(50% - var(--cover-size) / 2);
}
}
@layer components {
@layer warning {
/* Show warning for browsers without support */
.warning {
padding: 1em;
border: 1px solid black;
z-index: 9999;
color: black;
background: rgba(255 255 225 / 0.9);
z-index: 10001;
width: max-content;
margin: 0 auto;
}
:is(
.warning:hover,
.warning:has(:focus-within)
) {
opacity: 1;
}
.warning > :first-child {
margin-top: 0;
}
.warning > :last-child {
margin-bottom: 0;
}
.warning a {
color: blue;
}
.warning--info {
border: 1px solid #123456;
background: rgba(205 230 255 / 0.8);
}
}
@layer debug {
#debug {
position: absolute;
top: 1em;
left: 1em;
}
#debug::after {
content: " Show Debug";
margin-left: 1.5em;
color: white;
white-space: nowrap;
}
#debug:checked + .cards {
border: 1px solid lime;
}
#debug:checked + .cards li {
text-align: center;
color: white;
border: 1px solid blue;
}
#debug:checked + .cards li::before {
content: attr(id);
display: block;
position: absolute;
inset: 0;
line-height: var(--cover-size);
opacity: 0.5;
}
#debug:checked + .cards li img {
opacity: 0.5;
}
}
}
// Alternative Versions:
// - JS ScrollTimeline 2022: https://codepen.io/bramus/pen/MWVExQg
// - CSS view-timeline 2022: https://codepen.io/bramus/pen/GRdGoKy/
// - CSS view-timeline 2022 (fork) + scrollSnap JS event album title reveal: https://codepen.io/argyleink/pen/Rwzprzz 👈 = The version you are currently looking at
// - JS Motion One: https://codepen.io/bramus/pen/PoRKEaZ
// - CSS @scroll-timeline 2021 (Old Syntax): https://codepen.io/bramus/pen/xxRZZdK
// - JS ScrollTimeline 2021 (Old Syntax): https://codepen.io/bramus/pen/PobZbBV
// The JS below is so you can click and drag to scroll on desktop
// @source https://codepen.io/thenutz/pen/VwYeYEE
const slider = document.querySelector(".cards");
let isDown = false;
let startX;
let scrollLeft;
slider.addEventListener("scrollsnapchange", (e) => {
event.snapTargetInline.classList.add('snapped');
})
slider.addEventListener("scrollsnapchanging", (e) => {
slider.querySelector(':scope .snapped')?.classList.remove('snapped');
})
slider.addEventListener("pointerdown", (e) => {
isDown = true;
slider.classList.add("active");
startX = e.pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
});
slider.addEventListener("pointerleave", () => {
isDown = false;
slider.classList.remove("active");
});
slider.addEventListener("pointerup", () => {
isDown = false;
slider.classList.remove("active");
});
slider.addEventListener("pointermove", (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = (x - startX) * 3; //scroll-fast
slider.scrollLeft = scrollLeft - walk;
});
Also see: Tab Triggers