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.
<section class="header">
<div class="intro">
<div class="inner">
<h1>An Intro Text</h1>
<p>This will actually be a slider later on.</p>
</div>
</div>
<div class="cards">
<div class="card show">
<h2>Card One</h2>
<p>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi euismod in pharetra a ultricies in diam. Sed arcu. Cras consequat.</p>
</div>
<div class="card">
<h2>Card Two</h2>
<p>Praesent dapibus neque id cursus faucibus tortor neque egestas auguae eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi tincidunt quis accumsan porttitor facilisis luctus metus.</p>
<p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
</div>
<div class="card">
<h2>Card Three</h2>
<p>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam gravida non commodo a sodales sit amet nisi.</p>
</div>
</div>
</section>
<section class="additional">
<h2>Some more Infos</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh viverra non semper suscipit posuere a pede.</p>
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque felis.</p>
<p>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi euismod in pharetra a ultricies in diam. Sed arcu. Cras consequat.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
<p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
<p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
<p>Suspendisse mauris. Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Integer adipiscing risus a sem. Nullam quis massa sit amet nibh viverra malesuada. Nunc sem lacus, accumsan quis, faucibus non, congue vel, arcu. Ut scelerisque hendrerit tellus. Integer sagittis. Vivamus a mauris eget arcu gravida tristique. Nunc iaculis mi in ante. Vivamus imperdiet nibh feugiat est.</p>
<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Integer eu magna sit amet metus fermentum posuere. Morbi sit amet nulla sed dolor elementum imperdiet. Quisque fermentum. Cum sociis natoque penatibus et magnis xdis parturient montes, nascetur ridiculus mus. Pellentesque adipiscing eros ut libero. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p>
</p>
</section>
.header {
block-size: 100svh;
display: grid;
grid-template-areas: "main";
align-items: center;
background: url("https://images.unsplash.com/photo-1506452305024-9d3f02d1c9b5?q=80&w=1920&auto=format&fit=crop");
background-size: cover;
background-repeat: no-repeat;
background-color: #333;
}
.intro {
grid-area: main;
z-index: 1;
color: white;
margin: 2rem;
.inner {
max-inline-size: 65ch;
}
}
/*.cards-wrapper {
background-color: salmon;
padding: 2rem;
}*/
.cards {
margin-inline: 2rem;
grid-area: main;
z-index: 2;
display: grid;
grid-template-areas: "cards";
align-items: center;
background-color: #fff;
border-radius: 12px;
padding: 2rem;
opacity: 1;
pointer-events: none;
}
.card {
grid-area: cards;
z-index: 2;
opacity: 0;
pointer-events: none;
> * {
max-inline-size: 40ch;
}
&.show {
opacity: 1;
pointer-events: all;
}
}
.additional {
padding: 2rem;
* {
max-inline-size: 60ch;
}
}
/* ------------------
* Unrelated styling
* ------------------
*/
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui,
helvetica neue, Cantarell, Ubuntu, roboto, noto, helvetica, arial,
sans-serif;
}
h1,
h2,
h3,
h4 {
margin-block-start: 0;
margin-block-end: 1.25rem;
}
gsap.registerPlugin(ScrollTrigger);
document.addEventListener("DOMContentLoaded", init);
/*
* Initiate GSAP Timeline
*/
function init() {
// Define blank timeline
window.tl = gsap.timeline({
paused: true,
onComplete: () => {
// disable the Observer when the end of the timeline was reached
console.log("⏳ end of timeline reached, disabling observer...");
window.observer.disable();
}
});
window.animating = false;
// Add timeline entries
window.tl.addLabel("start");
window.tl.addLabel("hide intro, show card 1");
window.tl.to(".intro", { opacity: 0, duration: 0.5 });
window.tl.from(".cards", { translateY: "20vh", opacity: 0, duration: 0.5 });
window.tl.from(".card:nth-child(1)", { opacity: 0, duration: 1 });
window.tl.addLabel("showCard2");
window.tl.to(".card:nth-child(1)", { opacity: 0, duration: 0.5 });
window.tl.to(".card:nth-child(2)", { opacity: 1, duration: 1 });
window.tl.addLabel("showCard3");
window.tl.to(".card:nth-child(2)", { opacity: 0, duration: 0.5 });
window.tl.to(".card:nth-child(3)", { opacity: 1, duration: 1 });
window.tl.addLabel("end");
// An observer listens for scroll wheel or touch eventes and steps through our timeline labels
window.observer = Observer.create({
target: ".header", // can be any element (selector text is fine)
type: "wheel,touch,pointer", // comma-delimited list of what to listen for ("wheel,touch,scroll,pointer")
wheelSpeed: -1,
onDown: (self) => tweenToLabel(window.tl.previousLabel(), "down"),
onUp: (self) => tweenToLabel(window.tl.nextLabel(), "up"),
tolerance: 10,
preventDefault: true
});
console.log(
`after init: currentLabel ${window.tl.currentLabel()}, nextLabel ${window.tl.nextLabel()} `
);
}
/*
* Go to a label when not already animating
*/
function tweenToLabel(direction, moveDirection) {
console.log(
`tween from currentLabel ${window.tl.currentLabel()} -> nextLabel ${direction}`
);
if (!window.animating && direction) {
// Check if we're already animating
animating = true;
tl.tweenTo(direction, { onComplete: () => (window.animating = false) });
}
}
/*
* Pin the header and reenable Observer when returning
*/
ScrollTrigger.create({
trigger: ".header",
pin: true,
start: "top top",
end: "+=10",
onEnterBack: (self) => {
if (window.observer.isEnabled === false) {
self.scroll(self.start);
window.observer.enable();
tweenToLabel(window.tl.previousLabel());
}
}
});
Also see: Tab Triggers