Home › Developer Tools › CSS Flexbox Generator

CSS Flexbox Generator

Play with every flexbox property on a live layout, click any item to set its flex-grow, shrink, basis, order or align-self, and copy clean CSS and HTML. Runs entirely in your browser.

Last updated:

Presets

Container

Item 1

CSS

      
HTML

      
Advertisement

How to use the CSS Flexbox Generator

  1. Pick a preset or start with the basic row of four items.
  2. Set the container: choose flex-direction, wrap, justify-content, align-items and the gaps, and watch the preview update.
  3. Click an item in the preview to select it, then change its flex-grow, flex-shrink, flex-basis, order or align-self.
  4. Add or remove items to test how the layout behaves with more content.
  5. Press Copy CSS and Copy HTML to use the layout in your project.

Flexbox cheat sheet

PropertyApplies toDefaultWhat it controls
flex-directionContainerrowMain axis: row, row-reverse, column or column-reverse
flex-wrapContainernowrapWhether items may break onto new lines
justify-contentContainernormal (acts as flex-start)Spacing of items along the main axis
align-itemsContainernormal (acts as stretch)Position of items on the cross axis
align-contentContainernormal (acts as stretch)Spacing of wrapped lines on the cross axis
gapContainer0Space between items (row-gap and column-gap)
flex-growItem0Share of the free space the item takes
flex-shrinkItem1How much the item shrinks when space runs out
flex-basisItemautoStarting size before growing or shrinking
orderItem0Visual order (lower comes first)
align-selfItemautoOverrides align-items for one item

Worked example: how flex-grow shares space

A 900px wide row holds three items with flex-basis: 200px and no gap. Their bases add up to 600px, leaving 300px of free space. If the items have flex-grow values of 1, 1 and 1, each gets 300 ÷ 3 = 100px extra and ends up 300px wide. With values 2, 1 and 0, the free space is split into 3 shares of 100px: the first item becomes 200 + 200 = 400px, the second 200 + 100 = 300px and the third stays at 200px.

Shrinking works the other way, but is weighted by size: when items overflow, each shrinks in proportion to flex-shrink × flex-basis, so larger items give up more space. Set flex-shrink: 0 on anything that must keep its size, like a fixed sidebar.

Common flex shorthands

ShorthandEqualsUse it for
flex: initial0 1 autoThe default: size to content, may shrink
flex: 11 1 0%Equal-width columns
flex: auto1 1 autoGrow from content size
flex: none0 0 autoFixed size that never grows or shrinks
flex: 0 0 200px0 0 200pxFixed 200px sidebar

Need rows and columns at the same time? A grid layout is the better tool for full page templates. Tidy the final code with the CSS Formatter and HTML Formatter.

Frequently asked questions

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

justify-content distributes items along the main axis (horizontally for flex-direction: row), and align-items positions them on the cross axis (vertically for a row). When you switch to flex-direction: column, the axes swap.

When does align-content do anything?

Only when the container has flex-wrap: wrap (or wrap-reverse) and the items actually wrap onto more than one line, with extra space in the cross direction. It positions the lines as a group, much like justify-content does for items.

What does flex: 1 mean?

flex: 1 is shorthand for flex-grow: 1, flex-shrink: 1, flex-basis: 0%. Every item with flex: 1 starts from zero width and shares the free space equally, which is how you make equal-width columns.

What is the difference between flex-basis and width?

flex-basis sets the item's starting size along the main axis before free space is shared out, and it takes priority over width in a row (or height in a column). flex-basis: auto falls back to the item's width or its content size.

How do I center a div with flexbox?

Give the parent display: flex, justify-content: center and align-items: center, and give it a height. The child is centered horizontally and vertically. The Perfect center preset generates exactly that.

Does the order property affect accessibility?

Yes. order only changes the visual order; screen readers and keyboard Tab order still follow the HTML source. Use it for small visual tweaks, and change the HTML order when the reading order matters.

Should I use flexbox or CSS grid?

Use flexbox for one-dimensional layouts where items flow in a row or a column (navbars, toolbars, card rows, centering). Use CSS grid for two-dimensional layouts where you control rows and columns at the same time, such as page templates.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

CSS FormatterBeautify CSS with indent controls and optional property sorting.HTML FormatterBeautify and indent HTML code with a live preview.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.Open Graph PreviewPaste OG tags and preview how links look on Facebook, X and LinkedIn.YouTube Embed Code GeneratorCreate responsive YouTube embed code with start time, autoplay, loop and privacy mode.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.Twitter Card GeneratorCreate X / Twitter Card meta tags with Open Graph fallbacks, character counters and a live preview.CSS Grid GeneratorDraw CSS grid layouts: set tracks and gaps, drag to name areas, then copy the CSS and HTML.PX to REM ConverterConvert px to rem or em and back, with a 1-100px table and a whole-CSS converter.Glassmorphism CSS GeneratorDesign frosted-glass UI cards with blur, transparency and border sliders, then copy the CSS.CSS Text Shadow GeneratorLayer CSS text shadows with a live preview and neon, 3D, outline and retro presets.HTML to JSX ConverterConvert HTML to valid React JSX: className, htmlFor, style objects, self-closing tags and events.CSS Clip-Path GeneratorDraw CSS clip-path shapes by dragging points: polygons, circle, ellipse and inset. Copy the CSS.CSS Animation GeneratorCreate CSS keyframe animations from 23 presets with live preview, timing controls and Copy CSS.CSS Triangle GeneratorMake CSS triangles in 8 directions with the border trick or clip-path. Set size and color, copy CSS.CSS Loader GeneratorPick from 14 pure CSS spinners and loaders, set color, size and speed, then copy the HTML and CSS.Cubic Bezier GeneratorDrag the control points to design a CSS easing curve, compare it with linear and copy cubic-bezier().CSS Filter GeneratorAdjust blur, brightness, contrast, hue, sepia and drop-shadow on an image and copy the CSS filter.CSS Specificity CalculatorCalculate CSS selector specificity (a, b, c), including :is(), :not(), :has() and :where(), and compare.Google Maps Embed GeneratorTurn an address or coordinates into responsive Google Maps iframe embed code, no API key.Neumorphism CSS GeneratorDesign soft UI neumorphic shapes with live preview and copy the box-shadow CSS.SVG Wave GeneratorMake layered SVG waves for section dividers and export SVG, PNG or a CSS background.SVG Blob GeneratorGenerate random organic SVG blob shapes with gradients and export SVG, PNG or CSS clip-path.CSS Clamp GeneratorTurn min/max sizes and viewport widths into a fluid CSS clamp() value in rem and vw.CSS @font-face GeneratorTurn font files or URLs into ready-to-paste @font-face rules with weights, styles and a preview.CSS Media Query GeneratorBuild @media rules for widths, orientation, dark mode and hover, or get framework breakpoints.CSS Scrollbar GeneratorStyle scrollbars: width, colors, radius and hover, with ::-webkit-scrollbar and scrollbar-color CSS.CSS Sprite GeneratorPack many icons into one sprite sheet PNG and get CSS classes with background-position.CSS Text Gradient GeneratorMake gradient text with background-clip:text: color stops, angle, font preview and fallback CSS.CSS Toggle Switch GeneratorDesign pure-CSS toggle switches: size, colors, shape and animation. Copy accessible HTML + CSS.CSS Tooltip GeneratorBuild pure CSS tooltips: position, arrow, colors, padding and animation. Copy HTML and CSS.HTML Form BuilderDrag and drop form fields with labels and validation, then copy accessible HTML and CSS code.Iframe GeneratorCreate iframe embed code: size or responsive ratio, border, allow, sandbox, lazy load, live preview.PX to VW ConverterConvert pixels to vw and vh for any viewport size, and vw/vh back to px, with breakpoint tables.SVG to CSS Data URITurn SVG code into a small URL-encoded data URI for CSS backgrounds, with Base64 size comparison.SVG to JSXTurn SVG code into a clean React component: camelCase attributes, style objects, TypeScript.Tailwind CSS Cheat SheetSearchable Tailwind class to CSS reference with live previews, class decoder and color palette.Web App Manifest GeneratorCreate a PWA manifest.json and every app icon size from one image, downloaded as a ZIP.CSS Background Pattern GeneratorMake pure-CSS stripes, dots, checkerboard, zigzag and grid backgrounds and copy the code.CSS Color Filter GeneratorTurn a HEX color into a CSS filter that recolors black icons and SVGs, with an accuracy score.CSS Gradient Animation GeneratorCreate animated gradient backgrounds: pick colors, angle and speed, preview live and copy the CSS.CSS Hover Effects GeneratorPick button, link and image hover effects, tweak colors and timing, and copy the HTML and CSS.CSS InlinerMove CSS from style blocks into inline style attributes so HTML emails render in every client.CSS Shape Divider GeneratorCreate wave, tilt, curve and triangle section dividers and copy the SVG, HTML and CSS.CSS Transform GeneratorRotate, scale, skew and translate an element with sliders and copy the CSS transform code.Font Pairing ToolPreview Google Font heading and body pairs on real layouts and copy the embed code and CSS.HTML Accessibility CheckerPaste HTML to find WCAG accessibility problems with impact level, the failing element and a fix.HTML Image Map GeneratorDraw clickable rectangle, circle and polygon hotspots on an image and get image map HTML.SVG ViewerOpen or paste SVG code to preview it live with zoom, backgrounds, size info and PNG export.Pathfinding VisualizerAnimate BFS, DFS, Dijkstra, A* and greedy search on a grid with walls, weights and mazes.SVG Path EditorEdit an SVG path d attribute visually: drag points, edit commands, convert, scale and minify.
See all 52 Web, HTML & CSS Tools →