Skip to main content

CSS Flexbox Photo Gallery

Source Code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Photo Gallery</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="header">
<h1>css flexbox photo gallery</h1>
</header>
<div class="gallery">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/1.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/2.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/3.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/4.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/5.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/6.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/7.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/8.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/9.jpg">
</div>
</body>
</html>

What I Learned:

  • Using Flexbox (display: flex, flex-wrap, justify-content, gap) to create a responsive, beautiful gallery
  • Responsive layout tricks (max-width, margin auto)
  • Styling images with object-fit: cover and border-radius for a polished, modern look
  • The utility of pseudo-elements (::after) for layout control

Time: 1 hour 10 min total

Personal Note:
This is my favorite project so far — I absolutely love the way it looks. Seeing the visual result come together was really satisfying and motivating.
I'm now working on a vademecum: a living, real-world HTML & CSS handbook that I'll keep updating as I learn, always linking techniques to their everyday equivalents.

Next: Continue expanding the real-world HTML/CSS vademecum
and Learn Typography by Building a Nutrition Label