Responsive Web Design / CSS / Flexbox
Build a Flexbox Photo GalleryLet the collection fit the available space.
Watch Rob build the project, understand what each part is for, then work through the official freeCodeCamp workshop at your own pace.
ORIGINAL WALKTHROUGH · 28:26
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Current freeCodeCamp instructions are the reference when a recording differs. These guide topics are not timestamped video chapters.
THE IDEA BEHIND THE BUILD
What this workshop teaches
A gallery needs more than images placed next to each other. Its boxes must fit the container, its photos should keep their natural proportions and its rows should adapt when the available width changes. This workshop builds those decisions one at a time.
Begin with a visible box-sizing experiment, then remove the diagnostic rules and establish the real image frames. Use flex direction to understand the axes before applying wrapping and alignment. Object-fit controls the image inside each frame, gap separates the frames, and useful alternative text explains each photo’s content.
Reason about box sizing
Observe how borders and padding change a declared width under each model.
Use flex axes deliberately
Compare direction, wrapping, main-axis distribution and cross-axis alignment.
Fit and describe images
Crop without stretching and write meaningful alternatives for individual photos.

22 SMALL STEPS · THREE CLEAR GOALS
Your route through the workshop
These groups are a reading guide to the workshop, rather than timestamped chapters of the video.
Build and inspect the image boxes
Add the images and use temporary borders to compare sizing models.
Check your understanding: You can explain why border-box changes the outer width calculation.
Explore step 1Create the wrapping layout
Define image frames, page styling, flex axes, wrapping and container bounds.
Check your understanding: The layout responds to narrower space and each alignment property has a clear axis.
Explore step 9Refine the visible collection
Crop images, add gaps and corners, balance the final row and write alternatives.
Check your understanding: Photos keep their proportions and their relevant content is described.
Explore step 18SEE HOW THE PARTS FIT
A page with a clear structure
This original equipment-photo rule illustrates cropping within a differently sized image frame. It does not provide the completed cat gallery.
.equipment-photos img {
width: 280px;
height: 180px;
object-fit: cover;
}
/* The source keeps its proportions; edges may be cropped. */containerWrap and distribute the flex itemsimage boxChoose consistent rendered dimensionsimage contentFit without stretching its proportionsThree things to pay attention to
Axes depend on direction
Main and cross do not permanently mean horizontal and vertical.
Cover can crop important content
Inspect the visible subject after fitting the source to the chosen frame.
An alt-text length is only a minimum check
Describe what matters about each actual image instead of repeating generic text.
UNDERSTAND IT HERE · PRACTICE IT THERE
Explore each step
Choose a step for a plain-English explanation, a separate code example and resources to explore. When you are ready, its button opens the official freeCodeCamp step. Your official tests and completion stay on freeCodeCamp.
Step 1Connect the gallery stylesheet
UNDERSTAND THE IDEA
The supplied document needs its external style rules. A stylesheet link connects a CSS file to the document. A correct rule in an unlinked file will not affect the page.
What you will do
Link the requested stylesheet from the document head.
<link rel="stylesheet" href="swatches.css">What to notice: Use the actual filename supplied by the workshop. The example file and its rules belong to a different visual study.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 2Introduce the photo collection
UNDERSTAND THE IDEA
The collection starts with a recognizable page heading. A header introduces a page or section. A meaningful heading identifies the subject, while a class provides a separate styling hook.
What you will do
Add the requested header, class and main heading.
<header class="collection-intro">
<h1>Workshop equipment</h1>
</header>What to notice: This is a different collection, not the target photo-gallery heading. Semantic structure and presentation have separate roles.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 3Group the nine images
UNDERSTAND THE IDEA
The shared container will become the flex layout parent. A container holds the related images. Each image remains a distinct element with its own source and alternative text.
What you will do
Create the requested gallery container and nine image children.
<div class="equipment-photos">
<img src="soldering-station.jpg" alt="A soldering station beside a circuit board">
</div>What to notice: This partial equipment collection needs a real image file. It does not provide the gallery’s nine required images.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 4Give every photo a source
UNDERSTAND THE IDEA
The image order determines which supplied resource belongs to each element. A container holds the related images. Each image remains a distinct element with its own source and alternative text.
What you will do
Set the nine requested source URLs in document order.
<div class="equipment-photos">
<img src="soldering-station.jpg" alt="A soldering station beside a circuit board">
</div>What to notice: This partial equipment collection needs a real image file. It does not provide the gallery’s nine required images.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 5Make the box boundaries visible
UNDERSTAND THE IDEA
Temporary borders reveal how width, padding and border combine. Box sizing determines whether a declared width describes only the content or the content plus padding and border. Margins remain outside either calculation.
What you will do
Add the requested diagnostic gallery and image sizes, padding and colored borders.
.equipment-note { box-sizing: border-box; width: 360px; padding: 24px; border: 3px solid; }What to notice: With these different values, 360px includes padding and border. The remaining content width is 306px; external margins are additional.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 6Observe content-box sizing
UNDERSTAND THE IDEA
Content-box leaves padding and borders outside the specified content width. Box sizing determines whether a declared width describes only the content or the content plus padding and border. Margins remain outside either calculation.
What you will do
Set content-box explicitly with the universal selector and observe why the appearance does not change yet.
.equipment-note { box-sizing: border-box; width: 360px; padding: 24px; border: 3px solid; }What to notice: With these different values, 360px includes padding and border. The remaining content width is 306px; external margins are additional.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 7Include padding and border in the declared width
UNDERSTAND THE IDEA
The same declared width can describe a different sizing boundary. Box sizing determines whether a declared width describes only the content or the content plus padding and border. Margins remain outside either calculation.
What you will do
Change the universal box-sizing rule to border-box and compare the nested borders.
.equipment-note { box-sizing: border-box; width: 360px; padding: 24px; border: 3px solid; }What to notice: With these different values, 360px includes padding and border. The remaining content width is 306px; external margins are additional.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 8Remove the temporary diagnostics
UNDERSTAND THE IDEA
The boundary experiment has served its purpose. Removing an earlier declaration can reveal an inherited value, another matching rule or a browser default. CSS changes need to be understood in the surrounding cascade.
What you will do
Remove the temporary gallery and image rules while preserving the box-sizing reset.
.swatch {
width: 180px;
/* Color now comes from a variant rule. */
}What to notice: This snippet retains the geometry while leaving color to another rule. Do not remove unrelated declarations when the task asks for one property.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 9Give photos consistent rendered boxes
UNDERSTAND THE IDEA
A capped width and fixed height establish consistent frames. An empty block normally has no content height. Explicit dimensions can make an otherwise invisible colored box visible.
What you will do
Add the requested gallery-image width, maximum width and height.
.swatch { width: 180px; height: 30px; }What to notice: These dimensions differ from the marker and painting tasks. The visible outer size can also include borders and padding.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 10Reset the page surface
UNDERSTAND THE IDEA
A neutral page rule removes unwanted outside space. Browser defaults can add outer margins and a default typeface. A page-level rule gives the layout a deliberate starting surface.
What you will do
Apply the requested body margin, font family and background.
body { margin: 0; font-family: Arial, sans-serif; background: #edf5f7; }What to notice: These original colors and typography are for another page. Inspect text readability as well as the background.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 11Style the collection introduction
UNDERSTAND THE IDEA
The title should be distinct from the image collection. A distinct introduction helps separate the page title from the collection below. Color, padding and a boundary work together.
What you will do
Apply the requested header alignment, text transform, padding, colors and bottom border.
.collection-intro { padding: 24px; text-align: center; background: #173c59; color: #fff; border-bottom: 3px solid #7bcbd3; }What to notice: This original presentation is separate from the official gallery. Keep text contrast and readable spacing when adapting it.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 12Create the flex container
UNDERSTAND THE IDEA
The direct image children will become flex items. A flex container lays out its direct children as flex items. A nested container can establish a separate flex layout for its own children.
What you will do
Set the gallery display mode requested by the workshop.
.equipment-row { display: flex; }What to notice: This rule only establishes the layout mode. It does not automatically choose wrapping, spacing or a vertical alignment.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 13Choose the main axis
UNDERSTAND THE IDEA
Direction determines which axis the following alignment rules use. Flex direction defines the main axis. Row follows the inline direction of the writing mode; column follows the block direction.
What you will do
Experiment with the direction values, then set the requested explicit row direction.
.equipment-row { display: flex; flex-direction: column; }What to notice: This different example stacks items. Main and cross axes are relative to the chosen direction, not permanently horizontal and vertical.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 14Allow additional lines
UNDERSTAND THE IDEA
A narrower container should wrap items rather than demand one unbroken line. Wrapping allows flex items to form additional lines when they cannot fit on one. Item dimensions and shrink behavior still affect the result.
What you will do
Apply the requested wrapping behavior and resize the preview.
.equipment-row { display: flex; flex-wrap: wrap; }What to notice: Resize the available space to observe wrapping. Adding wrap alone does not guarantee a specific number of columns.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 15Center items along the main axis
UNDERSTAND THE IDEA
Free space can be distributed around each line’s items. Justify-content distributes available space along the main axis. Its effect depends on the direction and how much free space remains.
What you will do
Set the requested main-axis alignment on the gallery.
.equipment-row { display: flex; justify-content: space-around; }What to notice: This different distribution is not the project answer. Compare space around items with gaps and space inside an item.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 16Align items along the cross axis
UNDERSTAND THE IDEA
The row layout makes the cross axis vertical in the usual writing mode. Align-items sets the cross-axis alignment of the flex container’s items. Align-self can override that choice for one item.
What you will do
Set the requested cross-axis alignment on the gallery.
.equipment-row { display: flex; align-items: flex-start; }What to notice: The cross axis depends on flex-direction. Do not use this property as a synonym for horizontal centering.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 17Constrain and space the gallery
UNDERSTAND THE IDEA
The container needs both interior space and an outer width limit. Padding creates space inside a box’s border. With content-box sizing it adds to the declared content width and height.
What you will do
Add the requested padding, maximum width and centering margins.
.swatch-board { padding: 16px 8px; }What to notice: These different values show interior space. Compare padding with external margins and include it when reasoning about the outer dimensions.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 18Crop images without stretching them
UNDERSTAND THE IDEA
Different source aspect ratios should fit the same frame without distortion. Object-fit controls how an image’s content fits its rendered box. Cover preserves aspect ratio and fills the box by cropping when necessary.
What you will do
Apply the requested object-fit value and inspect which edges are cropped.
.equipment-photos img { width: 280px; height: 180px; object-fit: cover; }What to notice: The example has different dimensions. Cover can crop important content; it does not stretch the image or change the source file.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 19Add gutters between images
UNDERSTAND THE IDEA
Container gaps separate images without adding individual side margins. Gap creates gutters between flex items and lines. It does not add an equal outside margin around the container.
What you will do
Set the requested gap on the gallery flex container.
.equipment-row { display: flex; flex-wrap: wrap; gap: 18px; }What to notice: These different gaps separate items; use padding when the container also needs space inside its outer edges.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 20Round the image frames
UNDERSTAND THE IDEA
Consistent corners refine the repeated image boxes. Border-radius rounds the corners of a box. Its shorthand can set one radius or assign different radii in a defined corner order.
What you will do
Apply the requested image border radius.
.paint-block { border-radius: 12px 18px 10px 24px; }What to notice: The four values map to top-left, top-right, bottom-right and bottom-left. These sample values differ from the painting task.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 21Balance an incomplete final row
UNDERSTAND THE IDEA
An empty generated flex item can influence the last line’s distribution. An after pseudo-element generates a box after an element’s content when content is supplied. In a flex container it can participate as a flex item.
What you will do
Add the requested gallery after pseudo-element, empty content and width; inspect its effect at two-column sizes.
.equipment-row::after { content: ""; width: 280px; }What to notice: This empty spacer is a layout technique, not meaningful content. Its effect depends on item widths, wrapping and available space.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
Step 22Describe each photo meaningfully
UNDERSTAND THE IDEA
Accessibility requires relevant descriptions, not just a minimum number of characters. Alternative text communicates the relevant content or purpose of an image. Describe what matters in context rather than merely meeting a character count.
What you will do
Add an appropriate description to each of the nine images, meet the official length requirement and run the checks.
<img src="workbench.jpg" alt="A workbench with a soldering iron and safety goggles">What to notice: The filename is illustrative. Meaningful descriptions differ from one image to the next; decorative images need different treatment.
Resources to explore
Read another explanation or experiment with examples before trying the official step.
Ready to try it? Use freeCodeCamp’s exact requirements and run its checks there. The example above is for understanding the concept.
READY TO BUILD?
Keep the instructions beside the video.
Start the official workshop in a new tab, play the walkthrough here, and pause to make each change yourself. Run freeCodeCamp’s checks before moving on. Write and check your project in the official freeCodeCamp editor.
An independent walkthrough by The Code Zone. Not affiliated with or endorsed by freeCodeCamp. The project and official tests belong to freeCodeCamp; the explanations and visual guide on this page are our companion material.