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.
<h2>Try Scrolling to Bottom</h2>
<p>
<img class="alignleft" data-src="https://picsum.photos/id/1/200/150">
Consectetur adipisicing elit. Minus odio, obcaecati impedit voluptates rerum nisi reprehenderit dicta expedita in ut molestias cumque atque! Esse architecto. dolorem consequatur veniam provident modi. Dolor obcaecati nesciunt aperiam corrupti repellendus nihil illo velit voluptatem totam architecto sit eligendi, cumque eum animi eveniet id, veniam omnis necessitatibus explicabo ipsum assumenda expedita hic sunt! Reprehenderit nihil deserunt, incidunt facilis voluptates culpa suscipit illo.</p>
<p>
Commodi deserunt hic amet impedit vitae nemo, in enim sit, provident eius eligendi ullam molestiae asperiores quaerat doloremque nulla molestias? Assumenda iusto, sunt eaque natus accusamus deleniti magnam, dignissimos corporis impedit, officia
</p>
<img class="hero" data-src="https://picsum.photos/id/10/800/200">
<p>Incidunt cumque iure ab, voluptatem deserunt autem quibusdam similique sit cupiditate labore eaque, nihil voluptate asperiores dolorem.</p>
<p> <img class="alignright" data-src="https://picsum.photos/id/25/200/110"> Vero quae vitae excepturi voluptas aperiam perferendis eum doloribus dolores culpa aliquid, esse voluptatum cum quasi perspiciatis laborum harum, iste, totam modi. Quas quo corporis libero id harum quod earum, odio accusantium quia necessitatibus quos. Voluptate similique perferendis totam quod amet quasi rem veritatis vel ab sapiente. Necessitatibus tempora quisquam qui aperiam nesciunt totam delectus at in vitae!
</p>
<p>Fuga fugit sit dolores laboriosam, saepe natus eligendi voluptatem officiis dolor commodi maxime distinctio, eveniet minus consequuntur.</p>
<p>Dicta possimus nostrum quisquam veritatis unde voluptas quam doloribus a nemo ipsa! Assumenda odit eveniet totam molestias aliquam incidunt.</p>
<img class="hero" data-src="https://picsum.photos/id/50/800/300">
<h3>Deleniti beatae porro omnis eligendi molestias</h3>
<p>
<img class="alignleft" data-src="https://picsum.photos/id/75/200/120">
Ducimus aliquam totam provident maiores harum, sunt in excepturi atque eum maxime deserunt quasi! Culpa praesentium quia voluptatibus est, nemo possimus sapiente incidunt ad, deserunt veniam maxime, eius rem molestiae doloremque. Iste tenetur molestiae voluptate optio obcaecati, vitae.</p>
<p>
Consectetur adipisicing elit. Minus odio, obcaecati impedit voluptates rerum nisi reprehenderit dicta expedita in ut molestias cumque atque! Esse architecto.</p>
<img class="hero" data-src="https://picsum.photos/id/100/800/200">
<p>Incidunt cumque iure ab, voluptatem deserunt autem quibusdam similique sit cupiditate labore eaque, nihil voluptate asperiores dolorem. Perferendis mollitia illum cum ipsum quo, fuga aliquid ex porro reiciendis cupiditate rem ipsa error illo atque? Modi non, dolorum pariatur maiores praesentium amet eum alias neque nesciunt. </p>
<p><img class="alignright" data-src="https://picsum.photos/id/120/200/100">Vero quae vitae excepturi voluptas aperiam perferendis eum doloribus dolores culpa aliquid, esse voluptatum cum quasi perspiciatis laborum harum, iste, totam modi.
</p>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus molestiae voluptates, culpa, laboriosam cumque modi exercitationem laborum voluptatum.</p>
<img class="hero" data-src="https://picsum.photos/id/250/800/300">
body { padding: 1rem; max-width: 480px; }
p { font-size: 18px; }
img { max-width: 100%; }
.alignleft { float: left; margin-right: 1rem; }
.alignright { float: right; margin-left: 1rem; }
( function() { 'use strict';
let images = document.querySelectorAll('img[data-src]');
document.addEventListener('DOMContentLoaded', onReady);
function onReady() {
// Show above-the-fold images first
showImagesOnView();
// scroll listener
window.addEventListener( 'scroll', showImagesOnView, false );
}
// Show the image if reached on viewport
function showImagesOnView( e ) {
for( let i of images ) {
if( i.getAttribute('src') ) { continue; } // SKIP if already displayed
// Compare the position of image and scroll
let bounding = i.getBoundingClientRect();
let isOnView = bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth);
if( isOnView ) {
i.setAttribute( 'src', i.dataset.src );
if( i.getAttribute('srcset') ) {
i.setAttribute( 'srcset', i.dataset.srcset );
}
}
}
}
})();
Also see: Tab Triggers