Design an Image Search App in HTML CSS & JavaScript Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Image Search Application contains an input field, which takes the choice or type of the image for which the user is searching. When the user enters the search string and clicks on the button, the top 10 images are shown to the user. If the user wants more images, then there is a Generate More button through which more images can be generated. Preview ImagePreview of Image Search AppApproachCreate the Image Search App UI Structure using HTML Elements like <div>, <h1>, <input>, and <button>. Embed all the essential CDN links for external Fonts, etc.When the entire structure of the application is designed, then using CSS styling properties like box-shadow, padding, width, overflow, etc. style the application. Create transition effects, animations, loading spinner effects using keyframes, and more stying properties.In the JavaScript file, specify the API URL in the variable, retrieve the input element value, and validate the query with basic validation like if the input is not present, no images are present for the search query. Send the Request to the Unsplash API for the images using the searchImages() function, and receive the 10 images displayed in the card component. If the user wants to retrieve more images, then the moreImgFn() function retrieves more than 10 images. The images can be viewed in attractive modal form. Example: The below example describes the basic implementation for an Image Search App in HTML, CSS, and JavaScript. HTML <!DOCTYPE html> <html> <head> <title>GFG</title> <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"> <link rel="stylesheet" href= "https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="app-container"> <header> <h1 style="color: green;"> GeeksforGeeks </h1> <h2 style="color: #000;"> Image Search App </h2> <div class="search-bar"> <input type="text" id="searchInput" placeholder="Search for images"> <button onclick="searchImages()"> Search </button> </div> </header> <main id="imageContainer" class="animate__animated animate__fadeIn"> </main> <div class="load-more"> <button onclick="moreImgFn()"> Generate More </button> </div> </div> <div id="imageModal" class="modal"> <span class="close" onclick="closePreFn()"> × </span> <img id="modalImage" class="modal-content" alt="Image Preview"> </div> <script src="script.js"></script> </body> </html> CSS body { font-family: 'Montserrat', sans-serif; margin: 0; padding: 0; background: linear-gradient(to right, #4CAF50, #2196F3); color: #fff; } .app-container { max-width: 900px; margin: 50px auto; padding: 20px; background-color: rgba(255, 255, 255, 0.95); border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } header { text-align: center; margin-bottom: 20px; } h1 { margin: 0; font-size: 3em; font-weight: bold; } .search-bar { margin-top: 10px; margin-bottom: 20px; display: flex; justify-content: center; align-items: center; } input { padding: 20px; border: 2px solid #FF4961; font-size: medium; border-radius: 5px 0 0 5px; width: 60%; } button { padding: 30px 30px; margin-left: -2px; background: #FF595E; color: #fff; border: none; border-radius: 0 5px 5px 0; cursor: pointer; } main { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: stretch; } .card { flex: 0 0 calc(20% - 10px); margin-bottom: 20px; overflow: hidden; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); background: #fff; transition: transform 0.3s ease; display: flex; flex-direction: column; } .card img { width: 100%; flex: 1; object-fit: cover; } .load-more { text-align: center; margin-top: 20px; } button { padding: 10px 20px; background: #FF595E; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; } button:hover { background: #FF4961; } .modal { display: none; position: fixed; z-index: 1; padding-top: 20px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.9); } .modal-content { margin: auto; display: block; width: 80%; max-width: 800px; } .close { color: #fff; position: absolute; top: 10px; right: 25px; font-size: 2em; font-weight: bold; cursor: pointer; } .close:hover, .close:focus { color: #FF595E; text-decoration: none; cursor: pointer; } @media(max-width: 800px) { .card { flex: 0 0 calc(50% - 10px); } } @media(max-width: 600px) { .card { flex: 0 0 calc(100% - 10px); } } JavaScript const apiKey = "API_KEY"; let page = 1; function searchImages() { const imgName = document.getElementById("searchInput").value.trim(); if (!imgName) { alert("Please enter a search query."); return; } const url = `API_URL`; fetch(url) .then(response => response.json()) .then(data => { if (data.results.length === 0) { alert("No images found for the given search query."); } else { showImgFn(data.results); } }) .catch(error => console.error('Error fetching images:', error)); } function showImgFn(images) { const imageContainer = document.getElementById("imageContainer"); imageContainer.innerHTML = ""; images.forEach(image => { const card = document.createElement("div"); card.classList.add("card"); const img = document.createElement("img"); img.src = image.urls.regular; img.alt = "Image"; img.onclick = function () { preImgFn(image.urls.full); }; card.appendChild(img); imageContainer.appendChild(card); }); } function moreImgFn() { page++; searchImages(); } function preImgFn(imageUrl) { const m = document.getElementById("imageModal"); const mImg = document.getElementById("modalImage"); m.style.display = "block"; mImg.src = ""; mImg.src = imageUrl; mImg.onload = function () { mImg.onload = null; }; } function closePreFn() { const modal = document.getElementById("imageModal"); modal.style.display = "none"; } document.getElementById("searchInput").value = "Computer"; searchImages(); Output: Comment More infoAdvertise with us Next Article Design an Image Search App in HTML CSS & JavaScript G gpancomputer Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter JavaScript-Projects Dev Scripter 2024 +2 More Similar Reads Design a Recipe App in HTML CSS & JavaScript We will create an attractive and styled application that gives the recipe of food, and dishes entered by the user. The user needs to enter the required food name and click on the button. The application uses an External API to fetch the food recipe and represent it in an attractive form. The user ca 6 min read Design a Rotating Image Gallery App in HTML CSS & JavaScript We'll gather some images and build a gallery that can be rotated with straightforward buttons. To rotate the images to the right, we'll use the right button, and for left rotation, we'll use the left button. The process will be simple, allowing us to easily rotate the images using these buttons.Prev 3 min read Create a Resize and Compress Images in HTML CSS & JavaScript While using the GeeksforGeeks Write Portal to write articles, we need to upload the images. As we need to resize the image as per GeeksforGeeks's requirement, we search for different tools and websites on the internet to resize and compress the image. But, as a web developer, we can create our own i 7 min read Create a Lyrics Search App in HTML CSS & JavaScript A Lyrics Search Application contains an input field, which takes the input as Song Name or Artist Name. Once the user enters the search query, the API Request is made to lyrics.ovh, and then the response is retrieved with the first 5 songs list of the search query. Users can view the lyrics of any o 5 min read Build an AI Image Generator Website in HTML CSS and JavaScript Create an AI image generator website using HTML, CSS, and JavaScript by developing a user interface that lets users input text prompts and generate images by AI.We incorporated API integration to fetch data, providing users with an effortless and dynamic experience in generating AI-driven images. An 4 min read Search Bar using HTML CSS and JavaScript Every website needs a search bar through which a user can search the content of their concern on that page. We're going to learn how to create one using only HTML, CSS, and JavaScript. Instead of getting into complex algorithms for finding related content, we'll focus on a basic taskâsearching for s 3 min read Build A Weather App in HTML CSS & JavaScript A weather app contains a user input field for the user, which takes the input of the city name. Once the user enters the city name and clicks on the button, then the API Request is been sent to the OpenWeatherMap and the response is been retrieved in the application which consists of weather, wind s 7 min read Design a Online Cake Shop Website in HTML CSS & JavaScript Every business is going online nowadays for better growth and productivity. We are going to build an online cake shop website that will represent the shop in a good manner having features of online ordering and views and many more.PrerequisitesHTMLCSSJavaScriptApproachWe first create an HTML file wh 14 min read Design a Online Grocery Website in HTML CSS & JavaScript Online grocery shopping has become increasingly popular, especially in recent times. This project aims to create a user-friendly and responsive website for purchasing groceries online. Users can browse through the various categories, add items to their cart, and proceed to checkout making their groc 5 min read Design a Job Search Portal using HTML and CSS This article will show how to Job Portal static website using HTML, CSS, and JavaScript. We generally see these effects in portfolios of professionals. We have written a code that creates a customized job portal website. Users can easily search for job opportunities by category, and all available jo 3 min read Like