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.
<main>
<header class="inverted">
<h2>demo of anchor(auto) and position-fallback</h2>
<p>When you scroll the image caption (initially at top) out of viewport, it should be rendered below the image</p>
</header>
<section id="caption-auto-swap">
<!-- nice, this can be anywhere in the markup -->
<figcaption>
This image is generated by unsplash.it
</figcaption>
<h2>Implicit fallback positions with anchor(auto)</h2>
<img src="https://unsplash.it/1280/720" class="responsive-image">
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem mollis aliquam ut porttitor leo a diam sollicitudin. Ac placerat vestibulum lectus mauris ultrices eros. Lorem dolor sed viverra ipsum nunc aliquet bibendum. Convallis tellus id interdum velit laoreet id donec ultrices tincidunt. Vel elit scelerisque mauris pellentesque. Eget egestas purus viverra accumsan in. Tellus id interdum velit laoreet id. Elementum tempus egestas sed sed risus pretium quam vulputate dignissim. Bibendum enim facilisis gravida neque convallis a. Curabitur gravida arcu ac tortor dignissim. Risus commodo viverra maecenas accumsan. Tincidunt ornare massa eget egestas purus viverra.
</p>
</section>
<section id="caption-with-fallback">
<h2>Explicit fallback positions with position-fallback</h2>
<figcaption anchor="hero-image-anchor">
Another one by unsplash.it
</figcaption>
<img id="hero-image-anchor" src="https://unsplash.it/1280/720" class="responsive-image">
</section>
<section>
<p>
Id aliquet lectus proin nibh nisl condimentum id venenatis a. Tempor orci dapibus ultrices in iaculis nunc. Vitae tempus quam pellentesque nec nam aliquam. Maecenas volutpat blandit aliquam etiam erat velit scelerisque in dictum. Aenean pharetra magna ac placerat vestibulum lectus mauris ultrices eros. Diam ut venenatis tellus in metus vulputate. Varius morbi enim nunc faucibus a. Auctor elit sed vulputate mi sit amet mauris commodo quis. Interdum velit laoreet id donec ultrices tincidunt arcu. Feugiat nisl pretium fusce id velit ut tortor pretium. Non blandit massa enim nec. Sem integer vitae justo eget magna. Nulla facilisi nullam vehicula ipsum. Lectus quam id leo in vitae. Sed enim ut sem viverra. Eu scelerisque felis imperdiet proin fermentum leo vel orci. Fermentum iaculis eu non diam phasellus vestibulum lorem sed risus. Accumsan tortor posuere ac ut. Ultrices neque ornare aenean euismod elementum nisi.
</p>
<p>
Id consectetur purus ut faucibus pulvinar elementum integer enim neque. Quam quisque id diam vel quam. Eget sit amet tellus cras adipiscing enim eu turpis egestas. Nibh nisl condimentum id venenatis a condimentum vitae sapien. Integer eget aliquet nibh praesent tristique magna sit amet purus. Aliquet risus feugiat in ante metus. Duis ut diam quam nulla porttitor. Amet porttitor eget dolor morbi non. Euismod elementum nisi quis eleifend quam adipiscing vitae proin sagittis. Amet massa vitae tortor condimentum lacinia quis vel eros. Faucibus purus in massa tempor nec feugiat. Sit amet massa vitae tortor. Urna id volutpat lacus laoreet non curabitur.
</p>
<p>
Pharetra convallis posuere morbi leo urna molestie. Suscipit adipiscing bibendum est ultricies integer quis auctor elit. In iaculis nunc sed augue lacus viverra. Vitae semper quis lectus nulla at volutpat. Non consectetur a erat nam at lectus. Viverra orci sagittis eu volutpat odio. Tempor commodo ullamcorper a lacus. Felis donec et odio pellentesque diam volutpat commodo. Turpis egestas pretium aenean pharetra magna ac placerat vestibulum lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Quisque egestas diam in arcu cursus. Condimentum lacinia quis vel eros donec ac odio tempor. Arcu bibendum at varius vel pharetra. Eget arcu dictum varius duis at consectetur. Integer feugiat scelerisque varius morbi enim nunc faucibus a pellentesque. Ut eu sem integer vitae justo eget.
</p>
<p>
Amet porttitor eget dolor morbi non arcu risus quis varius. Enim sit amet venenatis urna cursus eget nunc scelerisque. Quis vel eros donec ac. Varius duis at consectetur lorem. Ut morbi tincidunt augue interdum. Fringilla ut morbi tincidunt augue interdum velit euismod. Nullam non nisi est sit amet facilisis. Sit amet nisl purus in mollis nunc sed id semper. Mauris rhoncus aenean vel elit scelerisque mauris pellentesque pulvinar. Curabitur vitae nunc sed velit dignissim sodales ut eu. Magna etiam tempor orci eu. Viverra adipiscing at in tellus integer feugiat. Tristique sollicitudin nibh sit amet commodo nulla facilisi. Nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum. Nulla pharetra diam sit amet nisl suscipit.
</p>
</section>
</main>
#caption-auto-swap {
margin-bottom: 2rem;
}
#caption-auto-swap img {
anchor-name: --hero-image-1;
}
#caption-auto-swap figcaption {
position: fixed; /* absolute does not work for some reason */
/* works only with anchor-default for some reason */
anchor-default: --hero-image-1;
/*
Align the fig caption’s bottom to the top of the anchor (hero image), but automatically swap if this overflows the window to the tooltip’s top aligns to the anchor’s bottom instead.
*/
bottom: anchor(auto);
left: anchor(left);
padding: .25em 0;
}
#caption-auto-swap figcaption::before {
content: "⬛️";
padding-right: .2em;
}
#caption-with-fallback img {
anchor-name: --hero-image-fallback;
}
#caption-with-fallback {
margin-bottom: 2rem;
}
#caption-with-fallback figcaption {
position: fixed;
anchor-default: --hero-image-fallback;
position-fallback: --fallback1;
}
#caption-with-fallback figcaption::before {
content: "⬛️";
padding-right: .2em;
}
@position-fallback --fallback1 {
@try {
top: anchor(bottom);
left: anchor(left);
border: 2px solid black;
}
@try {
bottom: anchor(top);
left: anchor(left);
border: 2px solid black;
}
}
Also see: Tab Triggers