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

              
                <div class="h-screen bg-gray-300">
  <div class="max-w-4xl p-8 mx-auto"
    x-data="alpineLightbox()" x-init="src = pixel" x-on:keydown.escape.window="close()">
    <!-- Start thumbnail grid -->
    <div class="grid grid-cols-2 gap-4 sm:gap-8 sm:grid-cols-3 md:grid-cols-4">
      <!-- Start thumbnail -->
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/09f/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/1200x630/09f/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
      <!-- End thumbnail -->
      
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/f09/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/1200x1200/f09/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/9f0/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/630x1200/9f0/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/90f/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/400x600/90f/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/f90/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/1200x630/f90/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
      <figure
        class="block w-full p-1 transition-shadow duration-200 ease-out bg-white border border-gray-300 rounded cursor-pointer hover:shadow-xl">
        <img class="block object-fill w-full h-full" src="https://via.placeholder.com/200/0f9/fff?text=Thumb"
          alt="Thumbnail" data-fullsize="https://via.placeholder.com/1200x1200/0f9/fff?text=Full+Size"
          x-on:click="open($event)">
      </figure>
    </div>
    <!-- End thumbnail grid -->

    <!-- Start lightbox -->
    <div
      class="fixed inset-0 z-50 grid w-screen h-screen gap-2 px-4 bg-black bg-opacity-75 sm:px-12 place-items-center grid-rows-lightbox"
      x-show="isOpen"
      x-transition:enter="transition ease-out duration-300"
      x-transition:enter-start="opacity-0"
      x-transition:enter-end="opacity-100"
      x-transition:leave="transition ease-in duration-300"
      x-transition:leave-start="opacity-100"
      x-transition:leave-end="opacity-0"
    >
      <img class="block object-contain w-full h-full row-start-2"
        x-bind:src="src"
        x-bind:alt="alt"
        x-show="isOpen"
        x-transition:enter="transition ease-out duration-300 delay-150"
        x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100"
        x-transition:leave="transition ease-in duration-300"
        x-transition:leave-start="opacity-100"
        x-transition:leave-end="opacity-0"
      >

      <button class="flex items-center p-2 text-white row-start-3" aria-label="Close" x-on:click="close()">
        <svg class="w-8 h-8 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"
          xmlns="http://www.w3.org/2000/svg">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
        </svg>
        <span class="text-xl font-light uppercase">Close</span>
      </button>

    </div>
    <!-- End lightbox -->

  </div>
</div>

              
            
!

CSS

              
                .grid-rows-lightbox {
  grid-template-rows: 3rem 1fr 3rem;
}
/*
Just one custom Tailwind class, can be added to tailwind.config.js instead of CSS:

module.exports = {
  // ...
  theme: {
    extend: {
      gridTemplateRows: {
				'lightbox': '3rem 1fr 3rem'
			}
    }
  }
  // ...
}
*/
              
            
!

JS

              
                window.alpineLightbox = function () {
  return {
    src: '',
    alt: '',
    isOpen: false,
    // One transparent pixel, to prevent broken img src: 
    pixel: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
    open($event) {
      // Get the clicked-on thumbnail
      const img = $event.target

      // Set the lightbox image src to the fullsize image
      this.src = img.getAttribute('data-fullsize')
      // Set the lightbox image alt attribute
      this.alt = img.getAttribute('alt')
      
      this.isOpen = true

      // Prevent the window from scrolling
      const html = document.documentElement;
      html.classList.add('h-screen', 'overflow-hidden', 'scroll-none');
    },
    close() {
      // Close lightbox
      this.isOpen = false
      
      // Return lightbox img src to transparent pixel
      this.src = this.pixel
      // Remove lightbox img alt attribute
      this.alt = ''

      // Return window to its normal state
      const html = document.documentElement;
      html.classList.remove('h-screen', 'overflow-hidden', 'scroll-none');
    }
  }
}
              
            
!
999px

Console