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

              
                <body x-data="imageGallery()" x-init="fetch('https://pixabay.com/api/?key=9158365-4702ac79e23be9aab580d1f9b&q=food&image_type=all&per_page=36')
  .then(response => response.json())
  .then(response => { images = response.hits })" class="bg-white">
  <!-- body starts-->
  <div class="main">
    <div class="container mx-auto px-4 sm:px-8 lg:px-16 xl:px-20">

      <!-- hero starts-->
      <section class="hero">

        <!-- hero headline starts -->
        <div class="hero-headline flex flex-col items-center justify-center pt-24 text-center">
          <h1 class=" font-bold text-3xl text-gray-900">Alpine.js Image Finder</h1>
        </div>
        <!-- hero headline ends -->


        <!-- image search box start -->
        <section class="search pt-8">
          <div class="search-wrapper">
            <div class="search-container bg-white rounded flex items-center w-full 
        p-3 shadow-sm border border-gray-200">

              <button @click="getImages()" class="outline-none focus:outline-none">
                <svg class=" w-5 text-gray-600 h-5 cursor-pointer" fill="none" stroke-linecap="round"
                  stroke-linejoin="round" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24">
                  <path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                </svg>
              </button>

              <input type="search" name="" id="" @keydown.enter="getImages()" placeholder="search for images"
                x-model="q" class="w-full pl-4 text-sm outline-none focus:outline-none 
          bg-transparent">

              <div class="select">
                <select name="" id="" x-model="image_type"
                  class="text-sm outline-none focus:outline-none bg-transparent">
                  <option value="all" selected>All</option>
                  <option value="photo">Photo</option>
                  <option value="illustration">Illustration</option>
                  <option value="vector">Vector</option>
                </select>
              </div>

            </div>
          </div>
        </section>
        <!-- image search box end -->


        <!-- Image grid starts-->
        <section id="photos" class="my-5 grid grid-cols-1 md:grid-cols-2 
lg:grid-cols-3 xl:grid-cols-4 gap-4">
          <template x-for="image in images" :key="image.id">

            <a :href="image.largeImageURL" class="hover:opacity-75 " target="_new">
              <img class="w-full h-64 object-cover" :src="image.largeImageURL" :alt="image.tags" />
            </a>

          </template>
        </section>
        <!-- Image grid ends-->
      </section>
      <!-- hero ends -->

      <!-- Footer starts-->
      <footer class="p-5 text-sm text-gray-600 flex justify-center items-center">
        <span class="text-teal-600 font-semibold">With</span>

        <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="heart"
          class="svg-inline--fa fa-heart fa-w-16 text-red-600 w-4 h-4 mx-2 align-middle" role="img"
          xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
          <path fill="currentColor"
            d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z">
          </path>
        </svg>

        <span class="text-teal-600 font-semibold">From Dailydotdev </span>
      </footer>
      <!-- Footer ends -->

    </div>
  </div>
              
            
!

CSS

              
                
              
            
!

JS

              
                    function imageGallery() {
      return {
        images: [],
        api_key: "9158365-4702ac79e23be9aab580d1f9b",
        q: "",
        image_type: "",
        page: "",
        per_page: 200,
        getImages: async function () {
          const response = await fetch(
            `https://pixabay.com/api/?key=${this.api_key}&q=${this.q}&
        image_type=${this.image_type}&per_page=${this.per_page}&page=${this.page}`
          );
          const data = await response.json();
          this.images = data.hits;
        }
      };
    }
              
            
!
999px

Console