Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <section class="gallery">
  <div class="container">
    <div class="toolbar">
      <div class="search-wrapper">
        <input type="search" placeholder="Search for photos">
        <div class="counter">
          Total photos: <span>12</span></div>
      </div>
      <ul class="view-options">
        <li class="zoom">
          <input type="range" min="180" max="380" value="280">
        </li>
        <li class="show-grid active">
          <button disabled>
            <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/grid-view.svg" alt="grid view">  
          </button>
        </li>
        <li class="show-list">
          <button>
            <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/list-view.svg" alt="list view">  
          </button>
        </li>
      </ul>
    </div>
    <ol class="image-list grid-view">
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature1.jpg" alt="">
          <figcaption>
            <p>green leafed trees</p>
            <p>Photo by <a href="https://unsplash.com/@redcharlie" target="_blank">redcharlie</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature2.jpg" alt="">
          <figcaption>
            <p>landscape photography of brown mountain</p>
            <p>Photo by <a href="https://unsplash.com/@wilstewart3" target="_blank">Wil Stewart</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature3.jpg" alt="">
          <figcaption>
            <p>blue starry night</p>
            <p>Photo by <a href="https://unsplash.com/@ignitedit" target="_blank">Mark Basarab</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature4.jpg" alt="">
          <figcaption>
            <p>aerial island and beaches</p>
            <p>Photo by <a href="https://unsplash.com/@phiestyphung" target="_blank">Amanda Phung</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature5.jpg" alt="">
          <figcaption>
            <p>forest pathway</p>
            <p>Photo by <a href="https://unsplash.com/@elke_karin" target="_blank">Elke Karin Lugert</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature6.jpg" alt="">
          <figcaption>
            <p>photo of two black, white, and orange koi fish</p>
            <p>Photo by <a href="https://unsplash.com/@s_sagano" target="_blank">Sora Sagano</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature7.jpg" alt="">
          <figcaption>
            <p>landscape photo of brown mountain</p>
            <p>Photo by <a href="https://unsplash.com/@darrylbrian" target="_blank">Darryl Brian</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature8.jpg" alt="">
          <figcaption>
            <p>moon illustration</p>
            <p>Photo by <a href="https://unsplash.com/@metatzon297" target="_blank">Shin Roran</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature9.jpg" alt="">
          <figcaption>
            <p>bird's eye view of body of water</p>
            <p>Photo by <a href="https://unsplash.com/@timmossholder" target="_blank">Tim Mossholder</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature10.jpg" alt="">
          <figcaption>
            <p>high-angle photography of rural area</p>
            <p>Photo by <a href="https://unsplash.com/@stlobe" target="_blank">Steven Wong</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature11.jpg" alt="">
          <figcaption>
            <p>silhoutte of mountains during sunset</p>
            <p>Photo by <a href="https://unsplash.com/@von_co" target="_blank">Ivana Cajina</a></p>
          </figcaption>
        </figure>
      </li>
      <li>
        <figure>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/unsplash_nature12.jpg" alt="">
          <figcaption>
            <p>bird's-eye view of mountain rang</p>
            <p>Photo by <a href="https://unsplash.com/@leni_eleni" target="_blank">Elena Prokofyeva</a></p>
          </figcaption>
        </figure>
      </li>
    </ol>
  </div>
</section>

<footer>
  <div class="container">
    <small>Made with <span>❤</span> by <a href="http://georgemartsoukos.com/" target="_blank">George Martsoukos</a>
    </small>
  </div>
</footer>
              
            
!

CSS

              
                /* RESET RULES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
:root {
  --black: #1a1a1a;
  --white: #fff;
  --gray: #ccc;
  --darkgreen: #18846C;
  --lightbrown: antiquewhite;
  --darkblack: rgba(0,0,0,0.8);
  --minRangeValue: 280px;
}

* {
  margin: 0;
  padding: 0;  
  outline: none;
  border: none;
}

button {
  cursor: pointer;
  background: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

ol,
ul {
  list-style: none;
}

a {
  color: inherit;
}

body {
  margin: 50px 0;
  color: var(--black);
  font: 1rem/1.3 sans-serif;
}

.gallery {
  padding: 0 2rem;
}

.container {
  max-width: 1030px;
  margin: 0 auto;
}

.d-none {
  display: none;
}


/* TOOLBAR
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar .search-wrapper {
  position: relative;
}

.toolbar input[type="search"] {
  font-size: 1.1rem;
  border: none;
  border-bottom: 1px solid;
  padding-bottom: 3px;
}

.toolbar ::placeholder {
  color: var(--gray);
}

.toolbar .counter {
  position: absolute;
  left: 0;
  top: calc(100% + 5px);
  font-size: 0.9rem;
  color: var(--gray);
}

.view-options {
  display: flex;
  align-items: center;
}

.view-options li:not(:last-child) {
  margin-right: 1.2rem;
}

.view-options button {
  padding: 2px;
  border: 3px solid transparent;
}

.view-options .active button {
  border-color: var(--darkgreen);
}


/* IMAGE LIST
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.image-list {
  margin: 3rem 0;
}

.image-list li {
  background: var(--lightbrown);
  color: var(--darkblack);
}

.image-list p:first-child {
  font-weight: bold;
  font-size: 1.15rem;
}

.image-list p:last-child {
  margin-top: 0.5rem;
}


/* GRID VIEW
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.grid-view {
  display: grid;
  grid-gap: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(var(--minRangeValue), 1fr));
}

.grid-view figcaption {
  padding: 1rem;
}


/* LIST VIEW
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.list-view li + li {
  margin-top: 1.5rem;
}

.list-view figure {
  display: grid;
  grid-gap: 1.5rem;
  grid-template-columns: 150px 1fr;
  align-items: center;
}


/* FOOTER
–––––––––––––––––––––––––––––––––––––––––––––––––– */
footer {
  font-size: 1rem;
  padding: 0 1.5rem;
  text-align: right;
}

footer span {
  color: #e31b23;
}

/* MQ
–––––––––––––––––––––––––––––––––––––––––––––––––– */
@media screen and (max-width: 900px) {
  .toolbar input[type="range"] {
    display: none;
  }
}

@media screen and (max-width: 700px) {
  .grid-view li {
    text-align: center;
    padding: 0.5rem;
  }
  
  .grid-view figcaption {
    padding: 0.5rem 0 0;
  }
}
              
            
!

JS

              
                // VARIABLES
const rangeInput = document.querySelector('input[type = "range"]');
const imageList = document.querySelector(".image-list");
const searchInput = document.querySelector('input[type="search"]');
const btns = document.querySelectorAll(".view-options button");
const photosCounter = document.querySelector(".toolbar .counter span");
const imageListItems = document.querySelectorAll(".image-list li");
const captions = document.querySelectorAll(".image-list figcaption p:first-child");
const myArray = [];
let counter = 1;
const active = "active";
const listView = "list-view";
const gridView = "grid-view";
const dNone = "d-none";

// SET VIEW
for (const btn of btns) {
  btn.addEventListener("click", function() {
    const parent = this.parentElement;
    document.querySelector(".view-options .active").classList.remove(active);
    parent.classList.add(active);
    this.disabled = true;
    document.querySelector('.view-options [class^="show-"]:not(.active) button').disabled = false;

    if (parent.classList.contains("show-list")) {
      parent.previousElementSibling.previousElementSibling.classList.add(dNone);
      imageList.classList.remove(gridView);
      imageList.classList.add(listView);
    } else {
      parent.previousElementSibling.classList.remove(dNone);
      imageList.classList.remove(listView);
      imageList.classList.add(gridView);
    }
  });
}

// SET THUMBNAIL VIEW - CHANGE CSS VARIABLE
rangeInput.addEventListener("input", function() {
  document.documentElement.style.setProperty("--minRangeValue",`${this.value}px`);
});

// SEARCH FUNCTIONALITY
for (const caption of captions) {
  myArray.push({
    id: counter++,
    text: caption.textContent
  });
}

searchInput.addEventListener("keyup", keyupHandler);

function keyupHandler() {
  for (const item of imageListItems) {
    item.classList.add(dNone);
  }
  const text = this.value;
  const filteredArray = myArray.filter(el => el.text.includes(text));
  if (filteredArray.length > 0) {
    for (const el of filteredArray) {
      document.querySelector(`.image-list li:nth-child(${el.id})`).classList.remove(dNone);
    }
  }
  photosCounter.textContent = filteredArray.length;
}
              
            
!
999px

Console