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

              
                 <main>
      <h1>Jared's Food</h1>
      <p>Click on an image to enlarge.</p>
   <p>
      <ul id="image_list">
        <li>
          <a href="https://shophomespice.com/images/ap_1.jpg" title="All Purpose Seasoning"
            ><img src="https://shophomespice.com/images/ap_1.jpg" alt="All Purpose Seasoning"
          /></a>
        </li>
        <li>
          <a href="https://shophomespice.com/images/bbq_1.jpg" title="BBQ Seasoning"
            ><img src="https://shophomespice.com/images/bbq_1.jpg" alt="BBQ Seasoning"
          /></a>
        </li>
        <li>
          <a href="https://shophomespice.com/images/card_1.jpg" title="Whole Cardomon"
            ><img src="https://shophomespice.com/images/card_1.jpg" alt="Whole Cardomon"
          /></a>
        </li>
        <li>
          <a href="https://shophomespice.com/images/uma_1.jpg" title="Umami Salt"
            ><img src="https://shophomespice.com/images/uma_1.jpg" alt="Umami Salt"
          /></a>
        </li>
        <li>
          <a href="https://shophomespice.com/images/red_1.jpg" title="Red Pepper Flakes"
            ><img src="https://shophomespice.com/images/red_1.jpg" alt="Red Pepper Flakes"
          /></a>
        </li>
      </ul>
   </p>
      <h2 id="caption"></h2>
      <p id="holder"><img src="" alt="" title="" id="main_image" /></p>
    </main>
              
            
!

CSS

              
                main{
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

ul{
  display: flex;
  justify-content: center;
}
li {

   list-style: none;
}
li img{
  width: 50%;
}
              
            
!

JS

              
                onload = () => {
  // getElementById function
  const $ = (id) => {
    return document.getElementById(id);
  };

  // Variables
  const listNode = $("image_list"); // ul element
  const captionNode = $("caption"); //h2 element
  const imageNode = $("main_image"); //main img element
  const holder = $("holder"); // get 'p' element
  let imageLinks = listNode.getElementsByTagName("a"); //grabs the links in the ul list
  [...imageLinks].forEach((imgLink) => {
    let height = 300;
    let width = 325;
    //Create the larger images
    let image = new Image(width, height);
    // Get href attribute of each img from image list
    image.src = imgLink.getAttribute("href");
    image.title = imgLink.getAttribute("title");
    // When you click on a thumbnail, larger img will appear
    //Click again and image will switch to new one
    imgLink.onclick = (e) => {
      e.preventDefault();
      holder.removeChild(holder.firstChild);
      holder.appendChild(image);
      captionNode.textContent = image.title;
    }; //end event handler
  }); //end 'foreach'
};
              
            
!
999px

Console