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.
<aside id="js-overlay" class="overlay">
<div id="js-overlay-target" class="overlay__inner"></div>
</aside>
<main>
<figure style="--color: #dfe7fd" onclick="toggleImageView(1)">
<div style="
background-image: url(https://images.unsplash.com/photo-1581260466152-d2c0303e54f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-1" class="gallery__image" src="https://images.unsplash.com/photo-1581260466152-d2c0303e54f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Peyto Lake, Canada</figcaption>
</figure>
<figure style="--color: #f8ad9d" onclick="toggleImageView(2)">
<div style="
background-image: url(https://images.unsplash.com/photo-1573057454928-f6eda06245ed?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-2" class="gallery__image" src="https://images.unsplash.com/photo-1573057454928-f6eda06245ed?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Two Jack Lake, Canada</figcaption>
</figure>
<figure style="--color: #d8e2dc" onclick="toggleImageView(3)">
<div style="
background-image: url(https://images.unsplash.com/photo-1571369985645-7859660074fa?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-3" class="gallery__image" src="https://images.unsplash.com/photo-1571369985645-7859660074fa?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Crail cottage in Mooroolbark, Australia</figcaption>
</figure>
<figure style="--color: #c1d3fe" onclick="toggleImageView(4)">
<div style="
background-image: url(https://images.unsplash.com/photo-1611029238634-0a9f540a94fd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-4" class="gallery__image" src="https://images.unsplash.com/photo-1611029238634-0a9f540a94fd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Icefields Parkway, Canada</figcaption>
</figure>
<figure style="--color: #d0f4de" onclick="toggleImageView(5)">
<div style="
background-image: url(https://images.unsplash.com/photo-1518495973542-4542c06a5843?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-5" class="gallery__image" src="https://images.unsplash.com/photo-1518495973542-4542c06a5843?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Sunlight passing through the tree</figcaption>
</figure>
<figure style="--color: #7bf1a8" onclick="toggleImageView(6)">
<div style="
background-image: url(https://images.unsplash.com/photo-1433086966358-54859d0ed716?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=700&q=50);
">
<img id="js-gallery-image-6" class="gallery__image" src="https://images.unsplash.com/photo-1433086966358-54859d0ed716?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1336&q=70" />
</div>
<figcaption>Bridge over a green waterfall</figcaption>
</figure>
</main>
html {
overflow: hidden;
}
body {
font-family: var(--font-body);
display: flex;
flex-direction: column;
font-family: "Roboto", sans-serif;
background-color: #fefae0;
overflow: auto;
color: #000;
}
main {
padding: 3rem 1rem;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 2rem;
max-width: 1280px;
margin: 0 auto;
font-family: "Barlow Condensed", sans-serif;
}
figure {
display: block;
cursor: pointer;
background-color: var(--color);
letter-spacing: 0.01rem;
border: 2px solid #111;
font-size: 24px;
font-weight: 700;
box-shadow: 5px 5px 0 1px #111;
}
figure div {
overflow: hidden;
position: relative;
background-color: hsl(0, 0%, 0%, 0.3);
aspect-ratio: 1;
background-position: 50% 50%;
background-size: cover;
}
figcaption {
padding: 1rem;
}
.overlay {
position: fixed;
display: flex;
align-items: center;
justify-content: center;
background-color: hsl(0, 0%, 0%, 0.7);
width: 100%;
height: 100vh;
z-index: 2;
padding-right: 17px;
cursor: pointer;
}
.overlay__inner {
padding: 2rem 1rem;
max-width: 1280px;
margin: 0 auto;
}
.overlay:not(.overlay--active) {
display: none;
}
.overlay .gallery__image {
margin: 0 auto;
max-height: calc(100vh - 4rem);
}
.gallery__image {
object-fit: cover;
object-position: 50% 50%;
aspect-ratio: 1;
}
/* CSS custom reset */
/*
1. Use a more-intuitive box-sizing model.
*/
*,
*::before,
*::after {
box-sizing: border-box;
}
/*
2. Remove default margin
*/
* {
margin: 0;
}
/*
3. Allow percentage-based heights in the application
*/
html,
body {
height: 100%;
}
/*
Typographic tweaks!
4. Add accessible line-height
5. Improve text rendering
*/
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
font-family: Arial, Helvetica, sans-serif;
}
/*
6. Improve media defaults
*/
img,
picture,
video,
canvas,
svg {
display: block;
max-width: 100%;
max-height: 100%;
}
/*
7. Remove built-in form typography styles
*/
input,
button,
textarea,
select {
font: inherit;
}
/*
8. Avoid text overflows
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
// Select static & shared page elements
const overlayWrapper = document.getElementById("js-overlay");
const overlayContent = document.getElementById("js-overlay-target");
function toggleImageView(index) {
const image = document.getElementById(`js-gallery-image-${index}`);
// Store image parent element
const imageParentElement = image.parentElement;
// Move image node from grid to modal
moveImageToModal(image);
// Create click listener on the overlay for the active image element
overlayWrapper.onclick = function () {
// Return the image to its parent element
moveImageToGrid(imageParentElement);
};
}
// Helper functions for moving the image around and toggling the overlay
function moveImageToModal(image) {
// Show the overlay
overlayWrapper.classList.add("overlay--active");
overlayContent.append(image);
}
function moveImageToGrid(imageParentElement) {
imageParentElement.append(overlayContent.querySelector("img"));
// Hide the overlay
overlayWrapper.classList.remove("overlay--active");
}
Also see: Tab Triggers