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.
<!-- Recreation of https://www.bram.us/2017/10/15/badass/ with CSS Scroll-Driven Animations -->
<ul class="titles transparent">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
</ul>
<ul class="titles fill">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
</ul>
<div class="panels">
<div class="panel"><img src="https://picsum.photos/seed/1/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/2/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/3/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/4/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/5/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/6/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/7/1600/900" alt="photo" height="900" width="1600"></div>
<div class="panel"><img src="https://picsum.photos/seed/8/1600/900" alt="photo" height="900" width="1600"></div>
</div>
<div class="warning">
<p>⚠️ Your browser does not support CSS Scroll-Linked Animations with <code>view-timeline</code>. Please use Chrome Canary 115+ to check out this demo.</p>
</div>
/* See https://brm.us/css-scroll-detection for details */
@property --scroll-position {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@property --scroll-position-delayed {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@keyframes adjust-pos {
to {
--scroll-position: 1;
--scroll-position-delayed: 1;
}
}
:root {
animation: adjust-pos 0.01s linear both; /* Duration added to cater for Firefox */
animation-timeline: scroll(root);
}
body {
transition: --scroll-position-delayed 0.15s linear;
--scroll-velocity: calc(
var(--scroll-position) - var(--scroll-position-delayed)
);
}
html {
background: #666;
}
html {
scroll-snap-type: y mandatory;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
ul {
list-style: none;
pointer-events: none;
line-height: 1;
display: block;
}
ul li {
display: block;
line-height: 1;
}
.panel {
scroll-snap-align: center;
height: 100dvh;
border: 2px solid #333;
background: rgb(0 0 0 / 0.15);
z-index: -1;
}
.panel img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
filter: brightness(30%);
}
@keyframes slide-up {
to {
translate: 0 var(--end-pos);
}
}
.titles {
position: fixed;
z-index: 2;
top: 50dvh;
font-size: 25dvh;
left: 0;
right: 0;
text-align: center;
animation: slide-up 0.01s linear; /* Duration added to cater for Firefox */
animation-timeline: scroll(root block);
font-family: impact;
text-transform: uppercase;
letter-spacing: 1px;
/* Calculate the part each child can occupy.
For 8 children, that’s 12.5%
*/
--num-children: 8;
--num-children-1: calc(var(--num-children) - 1);
--size-per-child: calc(100% / var(--num-children));
/* Because the text needs to be in the dead center,
we need to shift up the whole thing by half the size per child.
If not, it would start with the top edge of the whole box
aligned to the center. We want the text to be centered.
So in the case of 8 items that is from -6.25% to to -(100% - 6.25%).
This range still spans 100% in total, but it is slightly shifted up.
*/
--half-size-per-child: calc(var(--size-per-child) / 2);
--start-pos: calc(var(--half-size-per-child) * -1);
--end-pos: calc(-100% + var(--half-size-per-child));
translate: 0 var(--start-pos);
}
.titles.transparent {
color: transparent;
-webkit-text-stroke: 1px rgb(255 255 255 / 0.7);
text-stroke: 1px rgb(255 255 255 / 0.7);
}
.titles.fill {
color: hotpink;
/* Determine which element is currently in view. We do this based
on the current scroll-distance (exposed via --y-pos) and how
much space each child takes up.
*/
--y-per-child: calc(1 / var(--num-children));
--cur-child: calc((var(--scroll-position) / var(--y-per-child)) + 1);
--cur-child-1: calc(var(--cur-child) - 1);
/* To adjust the clip path we need to adjust the total range
that is spanned.
*/
--clip-min: 0;
--clip-max: calc(100% - var(--size-per-child));
--clip-per-child: calc(var(--clip-max) / var(--num-children));
--fix: calc(
var(--clip-per-child) / 8
); /* Not sure why I need a fix like this ¯\_(ツ)_/¯ */
--extra: 1%;
clip-path: inset(
calc((var(--cur-child-1) * var(--clip-per-child)) - var(--extra)) 0%
calc(
(100% - (var(--cur-child) * var(--clip-per-child)) - var(--fix)) -
var(--extra)
)
0%
);
}
/* And now, for the late scrolling part …*/
.titles li {
will-change: transform;
transform-origin: 50% 50%;
transform: skewY(calc(var(--scroll-velocity) * -75deg));
}
/* Show warning for browsers without support */
.warning {
border: 1px solid black;
z-index: 9999;
color: black;
background: rgba(255 255 225 / 0.9);
z-index: 1;
position: fixed;
top: 1em;
left: 1em;
right: 1em;
text-align: center;
}
.warning p {
margin: 1em 0;
}
/* Hide warning when native view-timeline support detected */
@supports (view-timeline: --works) {
.warning {
display: none;
}
}
Also see: Tab Triggers