CSS Free, no sign-up

Flexbox generator and playground

Change the flex properties of the container and of a selected item — the preview updates instantly and the ready-made CSS below follows along.

Result
Ready-made CSS
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: stretch;
  gap: 8px;
}

How to use it

  1. In the Container block choose flex-direction, flex-wrap, justify-content, align-items, align-content and gap. Use the “−” and “+” buttons to set 1 to 8 items.
  2. Click any item in the preview (or select it with Tab and Enter) — its flex-grow, flex-shrink, flex-basis, align-self and order fields appear.
  3. Watch the axes: justify-content works along the main axis and align-items along the cross axis; flex-direction changes which way those axes point.
  4. Press “Copy”. The code contains the .container rule plus .item:nth-child(N) rules only for items that have non-default values.

How it works

Container and items

An element with display: flex becomes a flex container and its direct children become flex items. The container sets the general rules (flex-direction, justify-content, align-items, gap), while each item is controlled by its own properties (flex-grow, flex-basis, align-self, order).

.container {
  display: flex;
  gap: 8px;
}

Main axis and cross axis

With flex-direction: row the main axis runs left to right and the cross axis runs top to bottom; with column they swap. justify-content distributes items along the main axis (flex-start, center, space-between, space-evenly), while align-items aligns them along the cross axis. The default align-items value is stretch: items grow to fill the container along the cross axis.

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

flex-grow, flex-shrink and flex-basis

flex-basis is the starting size of an item (with auto it uses width or the content size). If the container has free space left, flex-grow shares it out in proportion; if there is not enough room, flex-shrink squeezes the items. An item with flex-grow: 0 does not take extra space, and one with flex-shrink: 0 never shrinks.

.item {
  flex: 1 1 200px; /* grow shrink basis */
}

flex-wrap, gap and align-content

By default flex-wrap: nowrap keeps every item on one line and shrinks them when space runs out. With wrap, items move onto new lines. Once there are several lines, align-content decides how those lines are distributed inside the container; on a single-line container it has no effect. For spacing between items use gap instead of margin — there is no extra space left at the edges.

align-self and order

align-self overrides the cross-axis alignment for a single item without touching the others. order rearranges items visually without changing the HTML (the default is 0 and lower values come first). Keep in mind that order only changes how things look: tab order and screen readers still follow the HTML.

.item:nth-child(2) {
  align-self: flex-end;
  order: -1;
}

FAQ

What is the difference between justify-content and align-items?

justify-content distributes items along the main axis, while align-items aligns them along the cross axis. With flex-direction: column the axes swap, so justify-content works vertically and align-items works horizontally.

Why is align-content not working?

align-content only works when items are split across several lines: you need flex-wrap: wrap and the container must have free space beyond the height of the lines (for example, a fixed height). On a single-line container use align-items instead.

What does `flex: 1` mean?

flex: 1 is the same as flex: 1 1 0%: the item shares free space, may shrink, and starts from a size of zero. If you give flex: 1 to several items, they split the free space equally.

Does gap work in flexbox in every browser?

Yes, gap is supported for flexbox in all modern browsers (Safari since version 14.1). If you do not need to support old browsers, margin tricks for spacing are no longer necessary.

This topic in the HTML & CSS course

More CSS tools

CSS gradient generator Linear, radial and conic gradients: pick colors, angle and stops, then copy the code. CSS Grid generator Set columns and rows, gaps and alignment, then copy the ready-made grid code. CSS box-shadow generator Pick offset, blur, color and layers for a shadow, then copy the ready-made box-shadow code. Cubic-bezier generator Drag the control points of an easing curve and copy the ready-made CSS transition. SVG animation generator Pick a shape and an effect — get inline SVG and CSS keyframes ready to paste. CSS specificity calculator Type selectors to see their (a,b,c) weight, a color-coded breakdown and which rule wins. CSS box model visualizer See content, padding, border and margin as a DevTools-style diagram and copy the CSS. CSS transform generator Move, rotate, scale and skew an element, see its original position and copy the code. CSS clamp() calculator Enter min and max font size and viewport width — get a ready clamp() for fluid typography. Color contrast checker (WCAG) Check text and background contrast against WCAG AA and AAA, and fix a failing pair of colors. CSS clip-path generator Polygons, bevels, arrows and circles: drag control points on the live canvas and copy ready-made CSS. CSS glassmorphism generator Frosted glass effect: backdrop-filter blur, saturation, border highlight and clean CSS. CSS border-radius (Blob) generator Organic shapes and 8-value border-radius: tune horizontal and vertical corner radii. CSS Stacking Context & z-index Visualizer Why z-index: 9999 fails! Explore CSS Stacking Contexts in interactive 3D exploded layers with transform, opacity and isolation triggers. CSS aspect-ratio & object-fit Generator Eliminate squished images & CLS layout jumps: live aspect-ratio proportions and interactive object-position focal point. CSS Filters Studio & Generator Photo effects without design tools: blur, contrast, hue-rotate, sepia, and trending Instagram-style presets. OKLCH Color Picker & Palette Generator Perceptually uniform brightness & vibrant Display P3 colors: OKLCH picker, design system scales, and fallbacks. CSS Scroll-driven Animations Generator Scroll-linked animations without JavaScript: animation-timeline scroll() & view(), reading progress bar & reveal on scroll. CSS Container Queries (@container) Generator Beyond viewport media queries: components adapt directly to their parent container width. Live resizer & @container rules.
WhatsApp