A modern, responsive image search application that demonstrates API integration, asynchronous JavaScript, and responsive UI design concepts.
- Dynamic Image Search: Search for images using keywords
- Real-time Results: Fetches and displays images instantly
- Responsive Grid Layout: Beautiful masonry-style grid that adapts to all screen sizes
- Infinite Scroll: Automatically loads more images as you scroll
- Loading Indicators: Visual feedback during API requests
- Error Handling: Comprehensive error handling for API failures and network issues
- Full-size Image View: Click any image to view it in full size with modal overlay
- Modern UI: Glass morphism design with smooth animations and transitions
- Fetch API & Async/Await: Modern JavaScript for API requests
- DOM Manipulation: Dynamic content creation and updates
- CSS Grid & Flexbox: Responsive layout design
- CSS Animations: Smooth transitions and loading states
- Event Handling: Search, scroll, and click interactions
- Error Handling: Try-catch blocks and user-friendly error messages
- Responsive Design: Mobile-first approach with media queries
Image-Search-App/
├── index.html # Main HTML structure
├── styles.css # Responsive CSS with modern design
└── script.js # JavaScript logic and API integration
-
Get Unsplash API Key:
- Visit Unsplash Developers
- Create a free account and register your application
- Copy your Access Key
-
Configure API Key:
- Open
script.js - Replace
YOUR_UNSPLASH_ACCESS_KEYwith your actual API key:
this.API_KEY = 'your_actual_api_key_here';
- Open
-
Serve locally & open in browser: Modern browsers may block some fetch requests when opening files directly from disk. It's recommended to serve the folder with a simple static server and open http://localhost:8000.
Using Python 3 (recommended):
cd examples/Image-Search-App python3 -m http.server 8000 # then open http://localhost:8000
Or use VS Code Live Server or
npx http-server.
The app uses the Unsplash Search Photos API:
// Example API call structure
const response = await fetch('https://api.unsplash.com/search/photos', {
headers: {
'Authorization': `Client-ID ${API_KEY}`
}
});Parameters used:
query: Search term (e.g., "nature", "technology")page: Page number for paginationper_page: Number of results (12 per page)orientation: "landscape" for consistent layout
async performSearch(query) {
try {
const images = await this.fetchImages(query, page);
this.displayImages(images);
} catch (error) {
this.handleSearchError(error);
}
}if (!response.ok) {
throw new Error(`API Error: ${response.status} ${response.statusText}`);
}shouldLoadMoreImages() {
const scrollTop = window.pageYOffset;
const windowHeight = window.innerHeight;
const documentHeight = document.documentElement.scrollHeight;
return scrollTop + windowHeight >= documentHeight - 1000;
}.image-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 2rem;
}- Desktop: 4-5 columns with larger images
- Tablet: 2-3 columns with medium images
- Mobile: Single column with optimized spacing
- Touch-friendly: Large buttons and touch targets
- Performance: Lazy loading and optimized images
- Invalid API Key: Clear message to configure API key
- Network Errors: Retry functionality
- API Quota Exceeded: Informative message about limits
- No Results Found: Helpful suggestions for better search terms
- Empty Search Query: Validation with user feedback
Try these search terms to see the app in action:
- nature
- technology
- animals
- architecture
- food
- travel
- abstract
- minimal
✅ Infinite Scroll: Loads more images automatically ✅ Loading Indicators: Visual feedback during requests ✅ Full-size Image Modal: Click any image for larger view ✅ Keyboard Navigation: Enter to search, Escape to close modal ✅ Smooth Animations: Fade-in effects and hover states ✅ Accessibility: Proper focus states and ARIA attributes
- Chrome (recommended)
- Firefox
- Safari
- Edge
- Modern mobile browsers
- Colors and styling in
style.css - API parameters in
script.js - Grid layout breakpoints
- Animation timings and effects
After studying this example, you'll understand:
- Modern JavaScript async patterns
- RESTful API integration
- Responsive CSS Grid layouts
- DOM manipulation techniques
- Error handling strategies
- UX/UI best practices
Happy coding! 🎉