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.
h1 Parallax Sync Scrolling
p When you scroll to the bottom, each column's bottom margin will be aligned, despite having different heights.
.container
.blue.column
.red.column
.green.column
// three columns of different sizes scroll at different rates to sync their top and bottom borders.
@mixin bg($color) {
$light: darken($color, 12%);
$dark: darken($color, 16%);
background: repeating-linear-gradient(-45deg,
$light,
$light 10px,
$dark 10px,
$dark 20px
);
}
body {
margin: 0;
padding: 0;
background: repeating-linear-gradient(-45deg, darken(white, 4%), darken(white, 4%) 10px, darken(white, 6%) 10px, darken(white, 6%) 20px);
font-family: monospace;
}
h1, p {
text-align: center;
}
.container {
display: flex;
flex-direction: row;
width: 100%;
margin-bottom: 80px;
}
.column {
flex: 1 1 auto;
height: 100%;
padding: 20px;
color: #f0f0f0;
text-align: center;
font-size: 24px;
overflow: hidden;
&.blue {
height: 400vh;
@include bg(dodgerblue);
}
&.red {
height: 770vh;
@include bg(firebrick);
}
&.green {
height: 620vh;
@include bg(forestgreen);
}
}
function parallaxSync(selector){
// get selected elements and sort descending by height
const elements = [...document.querySelectorAll(selector)];
const descHeight = elements.sort((a,b) => b.getBoundingClientRect().height - a.getBoundingClientRect().height);
// anchor, the tallest element, will scroll normally
// links, all other elements, will scroll slower
const [ anchor, ...links ] = descHeight;
// this function's css transforms leverage position and top rules
links.forEach(el => {
Object.assign(el.style, {
position: 'sticky',
top: 0,
})
})
// add window scroll listener
window.addEventListener('scroll', e => {
const anchorRect = anchor.getBoundingClientRect();
// if anchor top is above viewport, apply parallax sync
if (anchorRect.height > window.innerHeight && anchorRect.top < 0){
// the ratio of pixels that the client is below the anchor's top
// will be used to calculate the offset of every link's top
const ratio = anchorRect.top / anchorRect.height;
// iterate each link that is smaller than the anchor
links.forEach(link => {
const linkRect = link.getBoundingClientRect();
// only apply parallax if the height is greater than the viewport
// and the link's bottom is below the viewport bottom
if (linkRect.height > window.innerHeight && window.innerHeight < linkRect.bottom){
// apply ratio to the link height - viewport height,
// matching the link's bottom to anchor's bottom
const diff = linkRect.height - window.innerHeight;
const offset = ratio * diff;
// apply the css transform which will be a negative px value
link.style.top = `${offset}px`;
}
})
}
});
}
parallaxSync('.column');
[...document.querySelectorAll('.column')].forEach(elem => {
elem.innerHTML = `
<h1>1.</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Volutpat consequat mauris nunc congue nisi vitae suscipit. Maecenas accumsan lacus vel facilisis volutpat est velit egestas dui. Ante in nibh mauris cursus. Scelerisque fermentum dui faucibus in ornare quam. Velit sed ullamcorper morbi tincidunt ornare. Arcu cursus vitae congue mauris rhoncus aenean. Tincidunt id aliquet risus feugiat. Sit amet volutpat consequat mauris nunc congue nisi. Adipiscing elit pellentesque habitant morbi tristique senectus et netus et. Vitae tempus quam pellentesque nec nam aliquam sem. In fermentum posuere urna nec tincidunt praesent semper feugiat. Turpis nunc eget lorem dolor sed.
</p>
<h1>2.</h1>
<p>
Lacinia at quis risus sed vulputate. Mi quis hendrerit dolor magna eget est lorem ipsum. In aliquam sem fringilla ut morbi tincidunt. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam. Semper auctor neque vitae tempus. Elit sed vulputate mi sit amet mauris commodo. Tristique nulla aliquet enim tortor. Habitasse platea dictumst vestibulum rhoncus est. Ac turpis egestas sed tempus urna et pharetra. Mollis nunc sed id semper risus in hendrerit gravida.
</p>
<h1>3.</h1>
<p>
Vulputate ut pharetra sit amet aliquam id diam. In fermentum posuere urna nec tincidunt praesent semper feugiat. Aliquam vestibulum morbi blandit cursus risus. Diam quam nulla porttitor massa. Elit sed vulputate mi sit amet. Quam elementum pulvinar etiam non quam lacus suspendisse faucibus. In nisl nisi scelerisque eu. Tellus mauris a diam maecenas sed. Egestas dui id ornare arcu odio ut sem. Vivamus arcu felis bibendum ut tristique et egestas. Mattis nunc sed blandit libero volutpat sed cras ornare arcu. Mauris vitae ultricies leo integer malesuada nunc. Lobortis elementum nibh tellus molestie nunc non blandit massa enim. Euismod quis viverra nibh cras pulvinar mattis nunc sed. Felis bibendum ut tristique et. Faucibus et molestie ac feugiat sed lectus.
</p>
<h1>4.</h1>
<p>
Aliquam vestibulum morbi blandit cursus risus at. A arcu cursus vitae congue mauris rhoncus. Sit amet consectetur adipiscing elit. Egestas purus viverra accumsan in nisl nisi scelerisque. Viverra mauris in aliquam sem fringilla. Cursus eget nunc scelerisque viverra mauris in. Eu mi bibendum neque egestas congue. Diam volutpat commodo sed egestas egestas fringilla. Habitasse platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper. Dolor sit amet consectetur adipiscing elit pellentesque habitant. Volutpat blandit aliquam etiam erat velit scelerisque in.
</p>
<h1>5.</h1>
<p>
Adipiscing bibendum est ultricies integer quis auctor. Fringilla phasellus faucibus scelerisque eleifend. At ultrices mi tempus imperdiet. Malesuada fames ac turpis egestas. In hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Gravida cum sociis natoque penatibus et magnis. Rhoncus est pellentesque elit ullamcorper dignissim cras. Volutpat commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Viverra adipiscing at in tellus integer feugiat. Iaculis at erat pellentesque adipiscing commodo elit at imperdiet dui. Ut eu sem integer vitae justo eget magna. Dui vivamus arcu felis bibendum ut tristique. Donec et odio pellentesque diam volutpat. Eget nulla facilisi etiam dignissim. Donec et odio pellentesque diam volutpat commodo sed. Ornare lectus sit amet est placerat in. Ullamcorper malesuada proin libero nunc consequat interdum. Mauris in aliquam sem fringilla.
</p>
<h1>6.</h1>
<p>
Ullamcorper a lacus vestibulum sed arcu non. Eleifend quam adipiscing vitae proin sagittis. Dui accumsan sit amet nulla facilisi morbi tempus iaculis urna. Feugiat nibh sed pulvinar proin. Nibh tellus molestie nunc non blandit massa. Urna molestie at elementum eu facilisis sed odio. Dictum sit amet justo donec enim. Ipsum faucibus vitae aliquet nec. In pellentesque massa placerat duis ultricies. Orci porta non pulvinar neque laoreet suspendisse interdum. Est ultricies integer quis auctor elit sed vulputate mi sit. Ut consequat semper viverra nam libero. Tellus integer feugiat scelerisque varius morbi. Lobortis elementum nibh tellus molestie nunc. Dui ut ornare lectus sit amet est placerat. Habitasse platea dictumst vestibulum rhoncus est pellentesque. Nunc sed augue lacus viverra. Dignissim diam quis enim lobortis. Sit amet nulla facilisi morbi tempus iaculis urna.
</p>
`
})
Also see: Tab Triggers