Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                .gallery__image {
  contain: paint;
}

.gallery__image--active {
  page-transition-tag: active-image;
}


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;
}
              
            
!

JS

              
                // Select static & shared page elements
const overlayWrapper = document.getElementById("js-overlay");
const overlayContent = document.getElementById("js-overlay-target");

async function toggleImageView(index) {
  const image = document.getElementById(`js-gallery-image-${index}`);

  // Apply the CSS class which contains the page-transition-tag before animation starts
  image.classList.add("gallery__image--active");

  // Store image parent element
  const imageParentElement = image.parentElement;

  // Initialize transition from the API
  const moveTransition = document.createDocumentTransition();

  // Move image node from grid to overlay
  await moveTransition.start(() => moveImageToModal(image));

  // Create click listener on the overlay for the active image element
  overlayWrapper.onclick = async function () {
    // Initialize transition from the API
    const moveTransition = document.createDocumentTransition();

    // Return the image to its parent element
    await moveTransition.start(() => moveImageToGrid(imageParentElement));

    // Remove the class which contains the page-transition-tag after animation ends
    image.classList.remove("gallery__image--active");
  };
}

// 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");
}

              
            
!
999px

Console