Explanation
- HTML Structure:
- The HTML structure includes a container with a title, a div with the ID
photo-gridfor displaying the photos, and a button for loading more photos.
- The HTML structure includes a container with a title, a div with the ID
- CSS Styling:
- The
.photo-gridclass uses CSS Grid to create a responsive grid layout for the photos. - The
imgelements within the grid are styled with rounded corners and a box shadow. - The
buttonis styled for a modern look with hover effects.
- The
- JavaScript Functionality:
- The
accessKeyvariable stores your Unsplash API access key. - When the DOM content is loaded, the
loadRandomPhotosfunction is called to fetch and display random photos. - The
loadPhotosButtonis set up with an event listener to load more photos when clicked. - The
loadRandomPhotosfunction fetches 10 random photos from the Unsplash API and appends them to thephoto-griddiv.
- The
Replace 'YOUR_UNSPLASH_ACCESS_KEY' with your actual Unsplash API access key. This script fetches random photos from Unsplash and displays them in a grid layout, allowing users to load more photos by clicking the button.