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

Auto Save

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

              
                <div id="cbwrap">
  <!-- (X) NOT IMPORTANT -->
  <h1 id="cbtitle">SIMPLE IMAGE GALLERY</h1>
  
  <!-- (A) GALLERY -->
  <div class="gallery">
    <img src="https://images.unsplash.com/photo-1456926631375-92c8ce872def?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDY2Mzk&ixlib=rb-1.2.1&q=80" title="Big Cate"/>
    <img src="https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDY2Mzk&ixlib=rb-1.2.1&q=80" title="Smol Cate"/>
    <img src="https://images.unsplash.com/photo-1568901346375-23c9450c58cd?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDY5NDI&ixlib=rb-1.2.1&q=80" title="Hamborgor"/>
    <img src="https://images.unsplash.com/photo-1528826194825-a71b700fe80b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDcxNDI&ixlib=rb-1.2.1&q=80" title="Not Orange"/>
    <img src="https://images.unsplash.com/photo-1586716246449-f7419351c8f6?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDcwNjQ&ixlib=rb-1.2.1&q=80" title="Eggs"/>
    <img src="https://images.unsplash.com/photo-1613334729651-a62ccd73def6?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTY5MDcxMTU&ixlib=rb-1.2.1&q=80" title="Potat"/>
  </div>
  
  <!-- (X) NOT IMPORTANT -->
  <div id="cbinfo">Visit <a href="https://code-boxx.com/responsive-image-gallery-html-css/" target="_blank">Code Boxx</a> for more details!</div>
</div>
              
            
!

CSS

              
                /* (A) GALLERY WRAPPER */
.gallery {
  /* (A1) GRID LAYOUT - 3 IMAGES PER ROW */
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-gap: 20px;

  /* (A2) OPTIONAL WIDTH RESTRICT */
  max-width: 1000px;
  margin: 0 auto;
  overflow: hidden;
}

/* (B) GALLERY IMAGES */
.gallery img {
  /* (B1) DIMENSION */
  width: 100%;
  height: 180px; /* optional */
  padding: 10px;

  /* (B2) COLORS */
  border: 1px solid #ddd;
  background: #fff;

  /* (B3) IMAGE RESIZE */
  /* cover | contain | fill | scale-down */
  object-fit: cover;
}

/* (C) ON SMALL SCREENS - 2 IMAGES PER ROW */
@media only screen and (max-width: 600px) {
  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* (D) OPTIONAL ZOOM ON HOVER */
.gallery img:hover {
  z-index: 9;
  transform: scale(1.3);
  /* linear | ease | ease-in | ease-out | ease-in-out */
  transition: transform ease 0.5s;
}

/* (E) FULLSCREEN MODE */
.gallery img.full {
  position: fixed;
  top: 0; left: 0; z-index: 999;
  width: 100vw; height: 100%;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.7);
}
.gallery img.full:hover {
  z-index: 999;
  transform: none;
}

/* (X) NOT IMPORTANT */
body{background: url(https://images.unsplash.com/photo-1502154882433-a614dba12819?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDA4Nzk0ODR8&ixlib=rb-4.0.3&q=85)}
#cbwrap{background:rgba(255,255,255,.9);width:600px;padding:30px;border-radius:10px}
*{box-sizing:border-box;font-family:arial,sans-serif}
body{padding:0;margin:0;border:0;min-height:100vh;display:flex;justify-content:center;align-items:center;background-size:cover;background-position:center;backdrop-filter:blur(10px)}
#cbtitle{margin:0 0 30px;padding:0;text-transform:uppercase}
#cbinfo{margin-top:30px;padding-top:15px;border-top:1px solid #ddd;font-size:13px;font-weight:700}
#cbinfo a{text-decoration:none;padding:5px;color:#fff;background:#a91616}
              
            
!

JS

              
                window.addEventListener("load", () => {
  for (let i of document.querySelectorAll(".gallery img")) {
    i.onclick = () => i.classList.toggle("full");
  }
});
              
            
!
999px

Console