Creating a filterable photo gallery is an excellent way to showcase images neatly and attractively on your website. In this article, we will explore how you can design a photo gallery using HTML, CSS, and JavaScript, optimizing the content for SEO so that your page can be easily indexed by search engines.
Filterable photo galleries are useful for several reasons:
Next, we will outline the steps to create your own filterable gallery.
First, we will start by creating the HTML structure for the gallery. We will use an unordered list to display our images.
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Galería de Fotos Filtrable</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Filterable Photo Gallery</h1> <input type="text" id="searchInput" placeholder="Filter by category..."> <ul id="gallery" class="gallery"> <li class="filter-item nature"><img src="https://picsum.photos/id/237/200/300" alt="Naturaleza 1"></li> <li class="filter-item nature"><img src="https://picsum.photos/id/32/200/300" alt="Naturaleza 2"></li> <li class="filter-item architecture"><img src="https://picsum.photos/id/43/200/300" alt="Arquitectura 1"></li> <li class="filter-item architecture"><img src="https://picsum.photos/id/54/200/300" alt="Arquitectura 2"></li> <li class="filter-item technology"><img src="https://picsum.photos/id/53/200/300" alt="Tecnología 1"></li> <li class="filter-item technology"><img src="https://picsum.photos/id/77/200/300" alt="Tecnología 2"></li> </ul> <script src="script.js"></script> </body> </html>
Next, we'll add some basic styles using CSS to enhance the appearance of the gallery.
body { font-family: Arial, sans-serif; } .gallery { display: flex; flex-wrap: wrap; list-style: none; padding: 0; } .filter-item { margin: 10px; } .filter-item img { width: 200px; height: auto; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); }
Finally, we'll implement the logic to filter the images using JavaScript.
document.getElementById('searchInput').addEventListener('keyup', function() { let filter = this.value.toLowerCase(); let items = document.querySelectorAll('.filter-item'); items.forEach(item => { if (item.classList.contains(filter) || filter === '') { item.style.display = ''; } else { item.style.display = 'none'; } }); });
To optimize your filterable photo gallery for SEO, consider the following tips:
Make sure each image has a descriptive alt attribute. This not only helps with accessibility but is also crucial for SEO, as search engines use this information to index your images.
If you are using a content management system (CMS), ensure that your image URLs are descriptive and contain relevant keywords.
Optimize images for web before uploading. Use formats like JPEG or WebP, and compress the images to improve site load speed.
Be sure to include relevant text near the gallery that explains the context of the images and utilizes appropriate keywords for better indexing.
Creating a filterable photo gallery using HTML, CSS, and JavaScript is a straightforward process that can enrich user experience on your website. By following the steps above and applying SEO techniques, you can ensure that your gallery is not only visually appealing but also easily accessible to search engines. Go ahead and implement it to improve your visual content presentation!
Page loaded in 45.83 ms