HTML Color Picker
Pick and convert colors between HEX, RGB, RGBA, HSL, and HSLA formats. Features interactive canvas, color harmonies, shades, tints, and save functionality
CSS Flexbox Generator is a free visual tool to build, learn, and export CSS flexbox layouts with live preview, full property support, preset layouts, and interactive editing.
Flexbox is one of those things that clicks immediately for some developers and remains persistently confusing for others for much longer than it should. The mental model is not complicated, but the property names are not self-explanatory, the axis system requires a small conceptual shift, and the difference between align-items and align-content is the kind of thing that sends people back to the documentation repeatedly even after years of use.
The fastest way to understand flexbox is to see it respond to changes in real time. This tool provides exactly that. Adjust a property, watch the layout update immediately, understand what each value actually does by watching it happen rather than reading about it.
Before flexbox, achieving common layout patterns required hacks. Vertically centering an element of unknown height involved absolute positioning and negative margins, or table-cell display tricks, or JavaScript measuring element dimensions and calculating offsets. Distributing space evenly across a row of items required calculating percentages and accounting for gutters manually. These were solved problems only in the sense that solutions existed. They were not good solutions.
Flexbox, introduced as a CSS module and now supported universally across browsers, provides a proper layout model for distributing space and aligning items within a container. It is one-dimensional, meaning it handles layout along a single axis at a time, either horizontal or vertical. For two-dimensional grid layouts, CSS Grid is the appropriate tool. For most component-level layout needs, nav bars, button groups, card rows, form controls, toolbars, centered content, flexbox handles them cleanly without workarounds.
Every flexbox layout starts with a container. Setting display: flex on an element makes it a flex container. Its direct children automatically become flex items and arrange themselves along the main axis according to the properties you set.
The main axis runs in the direction defined by flex-direction. The default is row, meaning left to right in left-to-right languages. Setting flex-direction: column changes the main axis to vertical. The cross axis is always perpendicular to the main axis.
This axis system is why justify-content and align-items do different things. justify-content controls alignment along the main axis. align-items controls alignment along the cross axis. If you are in row direction and want to center items horizontally, that is justify-content. If you want to center them vertically, that is align-items. Swap to column direction and those responsibilities swap with it, which is the source of most flexbox confusion in the early stages.
These properties go on the flex container and control how all the children are laid out together.
flex-direction sets the main axis direction. row and row-reverse arrange items horizontally. column and column-reverse arrange them vertically.
flex-wrap controls whether items stay on one line or wrap to additional lines when they exceed the container's width. nowrap is the default and keeps everything on one line, potentially causing overflow. wrap allows items to flow onto new lines. wrap-reverse wraps in the opposite direction.
justify-content distributes space along the main axis. flex-start and flex-end pack items to one end. center centers the group. space-between places equal space between items with none at the edges. space-around places equal space around each item. space-evenly distributes space so the gap between any two items, including the container edges, is equal.
align-items controls cross-axis alignment for a single line of items. stretch is the default and makes items fill the container's cross-axis dimension. center centers them. flex-start and flex-end align to the respective ends. baseline aligns items along their text baseline, which is useful for mixed-size elements that share text.
align-content does what align-items does, but applies to multiple lines of wrapped content rather than a single line. It has no effect when flex-wrap is set to nowrap.
gap sets the spacing between flex items without needing margins. It accepts one value for equal row and column gaps, or two values to set them independently.
These properties go on individual flex items and control how each one behaves within the container.
flex-grow determines how much of the available space an item should take relative to other items. A value of 1 on all items distributes space equally. A value of 2 on one item and 1 on others makes the first item take twice as much of the available space.
flex-shrink controls how items shrink when there is not enough space. The default is 1, meaning items shrink proportionally. Setting it to 0 prevents an item from shrinking below its defined size.
flex-basis sets the initial main-axis size of an item before growth and shrinkage are applied. It can be a fixed length, a percentage, or auto, which uses the item's content size as the starting point.
The shorthand flex combines all three: flex: [grow] [shrink] [basis]. The common value flex: 1 is shorthand for flex: 1 1 0, which distributes available space equally and allows shrinking. Understanding this shorthand is worth the time since it appears constantly in real codebases.
align-self overrides the container's align-items value for a specific item, allowing one item to align differently from the rest.
order changes the visual order of items without changing the HTML source order. Useful for responsive layouts where the visual arrangement differs from the document order.
flex-direction, flex-wrap, justify-content, align-items, and gap values.The preset layouts cover the patterns that come up most often: centered content, horizontal navigation, equal-width columns, sidebar with main content, and similar. These are worth reviewing even if you plan to customize further, because they demonstrate which property combinations produce which results.
Perfect centering. The layout problem that required the most creative workarounds before flexbox. Now it is two properties on the container:
display: flex;
justify-content: center;
align-items: center;
Equal-width columns. Apply flex: 1 to each item and they distribute available space equally regardless of content length.
Navigation bar. A row container with logo on the left and nav links on the right. justify-content: space-between handles the separation. align-items: center keeps everything vertically aligned regardless of differing element heights.
Sticky footer. A column flex container on the body or main wrapper with the main content set to flex: 1. The footer stays at the bottom of the viewport on short pages without absolute positioning.
Card grid that wraps. flex-wrap: wrap combined with a fixed flex-basis on each card and gap for spacing produces a wrapping grid that adjusts to available width without media queries for basic cases.
Flexbox handles the layout logic. The visual polish of those layouts involves other CSS properties working alongside it. Rounded corners on your flex container or items are a common combination, and the CSS Border Radius Generator handles that with the same visual editing approach. Depth on those components typically involves shadows, which the CSS Box Shadow Generator covers with live preview and layer control.
For testing how your generated flexbox CSS behaves with actual HTML content before it goes into a project, the Live Content Previewer lets you drop in both HTML and CSS together and see them render in the same place. Once the stylesheet is ready for production, the CSS Minifier handles compression without any build pipeline required.
A question that comes up often enough to address directly. Flexbox and CSS Grid are complementary tools, not competing ones, and the common guidance to use flexbox for one-dimensional layouts and Grid for two-dimensional ones is accurate but slightly incomplete.
Flexbox is content-driven. The items influence the layout. If you have a row of items of varying widths and you want them to naturally fill the available space based on their content, flexbox handles that well.
Grid is layout-driven. The container defines the structure and items fill into it. If you have a defined grid of rows and columns and you want items to occupy specific cells regardless of their content size, Grid is the right choice.
In practice, most interfaces use both. A page-level layout might use Grid to define the overall structure, with flexbox handling the internal layout of individual components within that structure.
justify-content controls alignment along the main axis, which is horizontal in the default row direction. align-items controls alignment along the cross axis, which is vertical in row direction. If you change flex-direction to column, the axes flip and so do the responsibilities of these two properties.
flex: 1 is shorthand for flex: 1 1 0. It sets flex-grow to 1 so the item expands to fill available space, flex-shrink to 1 so it can shrink if needed, and flex-basis to 0 so all available space is distributed proportionally from zero rather than from the item's content size.
Use flexbox for one-dimensional layouts where items flow along a single axis and the content influences how space is distributed. Use CSS Grid for two-dimensional layouts where you need precise control over both rows and columns simultaneously. Most real interfaces use both at different levels of the component hierarchy.
Yes. Flexbox has had full cross-browser support since around 2015 and requires no vendor prefixes in any browser in current use. The generated CSS from this tool works without modification in all modern browsers.