Flexbox Playground is an online flexbox editor

Flexible Box Layout (One-dimensional) (Style.css)

flex item 1
flex item 2
flex item 3
flex item 4
flex item 5
flex item 6
flex item 7
flex item 8

CSS Grid Layout (Two-dimensional)

grid item 1
grid item 2
grid item 3
grid item 4
grid item 5
grid item 6

Flexbox Use Examples (Style_1.css)

1. Setting Flexbox

To set up a flexbox layout, just set the display mode of the container.

Box 1
Box 2
Box 3

2. Setting direction

There are 4 possible types of directions that the elements of a flexbox can take:

Box 1
Box 2
Box 3

3. Justify content

These are the flexbox axis:

cross start cross end main start main end flex container 1 flex item 2 flex item main axis cross axis main size cross size

If the direction of the flexbox is row, the main axis is horizontal and the cross axis is vertical. If the direction of the flexbox is column, these are the opposite.

If the elements in a flexbox do not fill the container, you can use justify-content to decide how those elements will be distributed though the main axis. Possible values are:

Box 1
Box 2
Box 3

4. Align content

align-items works similar as justify-content, but it works on the cross axis, instead of the main axis. Possible valus are:

Box 1
Box 2
Box 3

5. Wrapping

By default, flexbox will fit all the items together. Using flex-wrap we can separate the items inside a flexbox into several rows. Possible values are:

Box 1
Box 2
Box 3

6. Shrinking

If the container is too small, the boxes will shrink. You can use flex-shrink to set the proportions for shrinking, in comparasion with the rest of boxes

Box 1
Box 2
Box 3

7. Growing

The opposite of shrinking if growing. When the flexbox makes the items fill the whole main axis, you can set up the proportions for each item.

Box 1
Box 2
Box 3

8. Flex basis

flex-basis sets the initial size of an item before CSS shrinks it or expands it. The value auto sizes it based on its content.

Box 1
Box 2
Box 3

9. Flex shorthand

You can set all flex-grow, flex-shrink and flex-basis using the shorthand flex

Box 1
Box 2
Box 3

10. Set order

Box 1
Box 2
Box 3

10. Override alignment

Aligment in the cross axis can be individually overriden with align-self

Box 1
Box 2
Box 3

Practical Examples (Style_2.css)

Blue borders denote parent flex containers
Red borders denote children

class="layout-horizontal flex-children"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal flex-children" with one child's contents being disproportionately lengthy

Box 1
Box 2
Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3
Box 4

class="layout-horizontal grow-children" with one child's contents being disproportionately lengthy using grow-children

Box 1
Box 2
Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3 Box 3
Box 4

class="layout-horizontal"

Box 1
class="flex-1"
Box 3
Box 4

class="layout-horizontal"

class="flex-1"
class="flex-2"
class="flex-3"
Box 4

class="layout-horizontal pack-start"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal pack-center"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal pack-end"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal space-between"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal space-between" with content of varying length

Box 1
Box 2 Box 2 Box 2 Box 2 Box 2 Box 2 Box 2 Box 2 Box 2
Box 3
Box 4

class="layout-horizontal space-around"

Box 1
Box 2
Box 3
Box 4

class="layout-horizontal flex-children"

class="align-box-start"
class="align-box-end"
class="align-box-center"
Box 4 (default is align-items: "stretch")

class="layout-horizontal flex-children"

class="align-box-baseline"
class="align-box-baseline"
class="align-box-baseline"
class="align-box-baseline"

class="layout-vertical flex-children" (set height on parent container)

Box 1
Box 2
Box 3
Box 4

class="layout-vertical flex-children"

class="align-box-start"
class="align-box-end"
class="align-box-center"
Box 4 (default is align-items: "stretch")

class="layout-horizontal pack-center"

class="align-box-center"
class="dead-center" (on parent)

Table like emulation

adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjk
adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjk
adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjk
adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjk
adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjk
adslfjasdjf alsdjf aljfasd lfadjasdlfjk
adslfjask
adslfjasldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfjkldfja sldfj aljf ladjaldjf alsdjf alsdjf aljfasd lfadjasdlfj
adslfjadjasdlfjk
adslfjjk
adslfjasdjf alsdjf aljfasd lfadjasdlfjk
adslfj asdjf alsdjf aljfasd lfa asdjf alsdjf aljfasd lfaask
adlfj
adslfjadjasdlfjk
adslfjjk asdjf alsdjf aljfasd lfa asdjf alsdjf aljfasd lfa asdjf alsdjf aljfasd lfa
adslfjasdjf alsdjf aljfassdjf alsdjf aljfassdjf alsdjf aljfasd lfadjasdlfjk
adslfj asdjf alsdjf sdjf alsdjf aljfassdjf alsdjf aljfassdjf alsdjf aljfasaljfasd lfa asdjf alsdjf aljfasd lfaask
adsdjf alsdjf aljfassdjf alsdjf aljfassdjf alsdjf aljfaslfj
adslfsdjf alsdjf aljfassdjf alsdjf aljfassdjf alsdjf aljfasjadjasdlfjk
adslfjjk sdjf alsdjf aljfassdjf alsdjf aljfassdjf alsdjf aljfasasdjf alsdjf aljfasd lfa asdjf alsdjf aljfasd lfa asdjf alsdjf aljfasd lfa