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.
<div class="ff-banner">
Scrolling in Firefox may be broken because of a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1737820">scroll-snap bug</a>. Fix has been pushed to Firefox Nightly and should be released soon.
</div>
<main class="content">
<h1 class="headline">Horizontal scrolling in a centered max-width container</h1>
<p>A boneless carousel is a popcorn of the mind. Extending this logic, the literature would have us believe that a crumby afternoon is not but a cave. A delivery can hardly be considered an attack luttuce without also being a triangle. This could be, or perhaps one cannot separate weapons from breathing cushions.</p>
<div class="gallery">
<div class="wrapper">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
<div class="item">15</div>
<div class="item">16</div>
</div>
</div>
<p>A mole is a bulldozer's brush. Ships are alright errors. They were lost without the corny lamb that composed their carbon. Extending this logic, the sidelong children comes from a drifting sunbeam.</p>
<div class="gallery alt-sizes">
<div class="wrapper">
<div class="item">
<img src="https://picsum.photos/id/25/650/365" alt="" />
</div>
<div class="item lg">
<img src="https://picsum.photos/id/10/650/365" alt="" />
</div>
<div class="item">
<img src="https://picsum.photos/id/50/650/365" alt="" />
</div>
<div class="item sm">
<img src="https://picsum.photos/id/466/650/365" alt="" />
</div>
<div class="item sm">
<img src="https://picsum.photos/id/888/650/365" alt="" />
</div>
<div class="item">
<img src="https://picsum.photos/id/25/650/365" alt="" />
</div>
<div class="item lg">
<img src="https://picsum.photos/id/77/650/365" alt="" />
</div>
<div class="item">
<img src="https://picsum.photos/id/42/650/365" alt="" />
</div>
<div class="item lg">
<img src="https://picsum.photos/id/98/650/365" alt="" />
</div>
<div class="item">
<img src="https://picsum.photos/id/440/650/365" alt="" />
</div>
<div class="item sm">
<img src="https://picsum.photos/id/111/650/365" alt="" />
</div>
<div class="item">
<img src="https://picsum.photos/id/250/650/365" alt="" />
</div>
</div>
</div>
<p>In ancient times authors often misinterpret the approval as an enarched spleen, when in actuality it feels more like a feeling bone. The zeitgeist contends that those cautions are nothing more than brokers. A trip of the metal is assumed to be a classless trouser. The septembers could be said to resemble unplumbed breaths.</p>
<p>An incurved health's leopard comes with it the thought that the chichi peak is a sauce. One cannot separate tortellinis from ain laborers. A credit is the effect of a tub. Some stilted needs are thought of simply as fiberglasses.</p>
<div class="gallery rtl">
<div class="wrapper">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
<div class="item">15</div>
<div class="item">16</div>
</div>
</div>
<p>The first faithless feeling is, in its own way, an hour. Some posit the prewar rocket to be less than keyless. In modern times a dinkies ocean without hydrofoils is truly a course of detached sticks. What we don't know for sure is whether or not authors often misinterpret the squash as a balanced writer, when in actuality it feels more like an uncapped buffet.</p>
</main>
body {
--space: 1rem;
--space-md: calc(var(--space) * 2);
--content-max-width: 60ch;
font-family: sans-serif;
font-size: 1.2rem;
line-height: 1.5;
}
.rtl {
direction: rtl;
}
main {
margin-block: 6rem;
}
.content {
display: grid;
grid-template-columns:
[full-start] 1fr
[content-start]
min(var(--content-max-width), 100% - var(--space-md) * 2)
[content-end]
1fr [full-end];
}
.content > * {
grid-column: content;
}
.content > * + * {
margin-block-start: var(--space);
}
.headline {
margin-block-end: var(--space-md);
font-family: "Palatino";
font-size: clamp(2rem, 6vw, 3.5rem);
font-weight: bold;
line-height: 1.125;
letter-spacing: -0.015em;
}
.gallery {
grid-column: full;
display: grid;
grid-template-columns: inherit;
padding-block: var(--space-md);
overflow-x: scroll;
overscroll-behavior-x: contain;
scroll-snap-type: x proximity;
scrollbar-width: none;
}
.gallery::-webkit-scrollbar {
inline-size: 0 !important;
display: none;
}
.gallery .wrapper {
grid-column: content;
display: flex;
align-items: center;
gap: var(--space);
}
.gallery .wrapper::after {
content: "";
align-self: stretch;
padding-inline-end: max(
var(--space),
(100vw - var(--content-max-width)) / 2 - var(--space)
);
}
.gallery .item {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: center;
inline-size: 100%;
max-inline-size: 25rem;
aspect-ratio: 16 / 9;
font-size: 2rem;
background: hotpink;
border-radius: 4px;
overflow: hidden;
}
.gallery.alt-sizes .item.lg {
max-inline-size: 35rem;
}
.gallery.alt-sizes .item.sm {
max-inline-size: 15rem;
}
.gallery img {
width: 100%;
height: 100%;
object-fit: cover;
}
@supports not (aspect-ratio: 1) {
.gallery .item::before {
float: left;
padding-top: 56.25%;
content: "";
}
.gallery .item::after {
display: block;
content: "";
clear: both;
}
}
.ff-banner {
display: none;
}
@-moz-document url-prefix() {
.ff-banner {
display: block;
padding: var(--space);
background-color: lightyellow;
text-align: center;
font-size: 0.9rem;
}
}
Also see: Tab Triggers