Flex Layout Playground
Run the Flex Layout Playground MicroSim Fullscreen Edit the Flex Layout Playground MicroSim with the P5.js Editor
About This MicroSim
The Flex Layout Playground allows learners to experiment with CSS flexbox properties and see immediate visual results. By manipulating controls and observing how colored boxes rearrange themselves, students build intuition for layout vocabulary rather than memorizing abstract definitions.
How to Use
Controls
-
Direction - Changes
flex-direction:row: Items flow left to right (default)row-reverse: Items flow right to leftcolumn: Items flow top to bottomcolumn-reverse: Items flow bottom to top
-
Justify - Changes
justify-content(main axis alignment):flex-start: Items packed at the startflex-end: Items packed at the endcenter: Items centeredspace-between: Equal space between itemsspace-around: Equal space around itemsspace-evenly: Equal space between and around items
-
Align - Changes
align-items(cross axis alignment):flex-start: Items aligned to startflex-end: Items aligned to endcenter: Items centeredstretch: Items stretch to fill containerbaseline: Items aligned by text baseline
-
Wrap - Toggles
flex-wrap:- Unchecked:
nowrap(all items on one line) - Checked:
wrap(items wrap to new lines)
- Unchecked:
-
Gap - Adjusts spacing between items (0-30px)
-
Add Item / Remove - Add or remove flex items (1-6 items)
-
Copy CSS - Copies the current CSS code to clipboard
CSS Panel
The dark panel in the upper right shows the CSS code that would produce the current layout. This updates in real-time as you change settings.
Embedding This MicroSim
You can include this MicroSim on your website using the following iframe:
1 | |
Learning Objectives
After using this MicroSim, learners will be able to:
- Identify how
flex-directioncontrols the main axis orientation - Predict how
justify-contentdistributes items along the main axis - Explain the difference between
align-itemsoptions - Apply appropriate flexbox properties to achieve desired layouts
- Translate visual layouts into CSS code
Suggested Activities
Activity 1: Explore Each Property
Change one property at a time while keeping others at default. Observe and describe what happens.
Activity 2: Recreate Layouts
Try to recreate these common layouts: - Navigation bar (items spread across) - Centered content (both axes) - Sidebar layout (column direction)
Activity 3: Predict and Test
Before changing a property, predict what will happen. Then test your prediction.
Activity 4: CSS Translation
Look at the CSS panel and try to describe what each property does in your own words.
Key Concepts
Main Axis vs Cross Axis
- Main Axis: The primary direction items flow (
flex-direction) - Cross Axis: Perpendicular to the main axis
justify-contentworks on the main axisalign-itemsworks on the cross axis
Space Distribution
space-between: No space at edges, equal space betweenspace-around: Half space at edges, full space betweenspace-evenly: Equal space everywhere
Lesson Plan
Grade Level
High School (9-12) or introductory web development courses
Prerequisites
- Basic understanding of HTML
- Familiarity with CSS syntax
Duration
15-20 minutes for guided exploration
Procedure
-
Introduction (3 min): Explain that flexbox is a CSS layout system for arranging items in rows or columns.
-
Guided Exploration (7 min): Walk through each property as a class, predicting outcomes before testing.
-
Independent Practice (5 min): Students experiment freely and note observations.
-
Discussion (5 min): Share discoveries and discuss real-world applications.
Assessment
Ask students to describe what CSS properties they would use to: - Center a button horizontally and vertically - Create a navigation bar with evenly spaced links - Stack cards vertically with gaps between them