CSS Flexbox-Generator
Bauen Sie Flexbox-Layouts visuell · passen Sie Container- und Item-Eigenschaften an, sehen Sie eine Live-Vorschau und kopieren Sie das CSS.
Container-Eigenschaften
Live-Vorschau
Generiertes CSS
So funktioniert es
- Container-Eigenschaften setzen: Konfigurieren Sie den Flex-Container, flex-direction, justify-content, align-items, flex-wrap und gap.
- Flex-Items hinzufügen und konfigurieren: Fügen Sie Kindelemente hinzu und legen Sie individuelle Werte für flex-grow, flex-shrink, flex-basis, align-self und order fest.
- CSS kopieren: Holen Sie sich das vollständige CSS für Container und Items, einsatzbereit für Ihr Projekt.
Warum den Flexbox-Generator nutzen?
Flexbox ist das wesentliche Werkzeug für eindimensionale CSS-Layouts, Elemente in einer Zeile oder Spalte ausrichten, mit kraftvollen Steuerungen für Verteilung und Ausrichtung. Doch die Eigenschaften sind zahlreich und ihr Zusammenspiel komplex: justify-content gegen align-items, flex-grow gegen flex-basis, Hauptachse gegen Querachse. Dieser interaktive Generator gibt sofortiges visuelles Feedback beim Umschalten jeder Eigenschaft, der schnellste Weg, Flexbox zu lernen und passendes CSS für Ihr Layout zu erhalten.
Funktionen
- Interaktive Vorschau: Flex-Items verschieben und Eigenschaften umschalten, um Layout-Änderungen in Echtzeit zu sehen.
- Alle Container-Eigenschaften: flex-direction, flex-wrap, justify-content, align-items, align-content und gap.
- Steuerung pro Element: flex-grow, flex-shrink, flex-basis, align-self und order individuell pro Element festlegen.
- Visuelle Achsen-Indikatoren: Haupt- und Querachse werden hervorgehoben, um das gedankliche Modell zu festigen.
- CSS-Ausgabe: vollständiges, kopierbereites CSS für Container und alle konfigurierten Items.
Häufige Fragen
Was ist der Unterschied zwischen justify-content und align-items?
justify-content verteilt Items entlang der Hauptachse (standardmäßig horizontal). align-items richtet Items entlang der Querachse aus (standardmäßig vertikal). Steht flex-direction auf column, vertauschen sich die Achsen, justify-content wird vertikal, align-items wird horizontal.
Wann sollte ich Flexbox und wann CSS Grid einsetzen?
Nutzen Sie Flexbox für eindimensionale Layouts, eine Reihe von Buttons, eine Navigationsleiste, eine Liste umbrechender Karten. Nutzen Sie CSS Grid für zweidimensionale Layouts, bei denen Sie Zeilen und Spalten gleichzeitig steuern müssen, etwa ein vollständiges Seitenlayout oder ein komplexes Karten-Raster.
Was bedeutet flex: 1?
flex: 1 ist die Kurzform für flex-grow: 1; flex-shrink: 1; flex-basis: 0%. Sie weist das Element an, den verfügbaren Platz zu füllen, bei Bedarf zu schrumpfen und vor der Verteilung mit Größe null zu starten. Alle Items mit flex: 1 teilen sich den Platz gleichmäßig.
Was ist Flexbox?
Flexbox (Flexible Box Layout) is a CSS layout model designed for distributing space and aligning items in a one-dimensional direction: either a row or a column. It introduces two core concepts that determine how everything behaves: the main axis (the primary direction items flow, horizontal by default) and the cross axis (perpendicular to main, vertical by default). Once you internalize main vs cross, every Flexbox property maps to one of them: justify-content works on the main axis, align-items works on the cross axis, flex-direction swaps which axis is which.
Flexbox solved a set of layout problems that plagued web developers from 1998 to 2014. Before Flexbox, centering an element vertically required hacks (display: table-cell, negative margins, position: absolute with translate transforms). Equal-height columns required the "faux columns" technique with background images. Sticky footers needed precise pixel calculations. Flexbox made all of these trivial: a one-line declaration replaces decades of CSS workarounds. The trade-off is that Flexbox is one-dimensional; for two-dimensional layouts (row AND column simultaneously), CSS Grid (shipped 2017) is the better tool.
Flexbox properties divide cleanly into two groups: container properties (applied to the parent: display: flex, flex-direction, flex-wrap, justify-content, align-items, align-content, gap) and item properties (applied to children: flex-grow, flex-shrink, flex-basis, align-self, order). The container properties control layout patterns; the item properties control individual exceptions. This generator surfaces both sets so you can experiment with how they interact without writing code.
Was im Generator steckt
The live preview is a flex container with sample child elements. As you change container properties (flex-direction, justify-content, etc.) via dropdowns and inputs, JavaScript updates the inline style of the preview container, and the browser re-renders the layout. The preview is the actual browser's Flexbox implementation, not a JavaScript simulation: you see exactly what your CSS will produce on a real page.
Per-item controls let you adjust each child individually. You can add or remove items, set their flex-grow, flex-shrink, flex-basis, align-self, and order values, and see how the container redistributes space accordingly. Visual axis indicators show the main and cross axes for the current configuration, reinforcing the mental model. The properties are real CSS that you can copy directly into your stylesheet, no transpilation or framework prefixes needed.
The Generated CSS panel updates with each interaction, producing two CSS rules: one for the container (with the chosen flex properties) and one for the items. Click Copy CSS and the rules are written to your clipboard. The tool itself never makes network requests; the preview rendering, code generation, and clipboard write all happen in JavaScript on your device. Refresh the page and your configuration is gone unless you copied the CSS first.
Geschichte und Hintergrund
- CSS 2.1 layout chaos, 1998 to 2008. Before Flexbox, web developers used
float: leftwith clearfix hacks,display: inline-blockwith whitespace bugs, ordisplay: tablewith table-cell tricks for layout. Vertical centering requiredvertical-alignon table-cells, negative margin tricks, or absolute positioning. Equal columns required JavaScript. The web community generates thousands of blog posts about "how to do X with CSS" workarounds. - First Flexible Box draft, 2009. The W3C CSS Working Group publishes the first Working Draft of CSS Flexible Box Layout Module in July 2009, with three syntaxes evolving over the next five years: the original
box-*syntax (rapidly deprecated), the 2011flexboxintermediate syntax (still seen in legacy IE 10 code), and the finalflexsyntax we use today. - Browser support stabilizes, 2014. Chrome 29, Firefox 28, Safari 9, and IE 11 all ship working Flexbox by 2014, with IE 11 retaining buggy edge cases. The transition from "Flexbox is the future" to "Flexbox is the present" happens in 2014-2015 as production sites adopt it for major layouts. The "Holy Grail Layout" (header, footer, two sidebars, main content) becomes trivial.
- Chris Coyier's "A Complete Guide to Flexbox", 2013. CSS-Tricks publishes Chris Coyier's comprehensive Flexbox guide (April 2013), which becomes the canonical reference. By 2016, the guide is among the top results for any Flexbox question and is translated into dozens of languages. It dramatically accelerates Flexbox adoption.
- CSS Grid arrives as complement, 2017. CSS Grid Layout ships in Chrome 57, Firefox 52, and Safari 10.1 (March 2017). Far from replacing Flexbox, Grid complements it: Flexbox excels at one-dimensional row/column layouts, Grid excels at two-dimensional layouts. Modern designs typically use both: Grid for page-level structure, Flexbox for component-internal arrangements (nav items, button groups, card content).
- gap property and subgrid land, 2020 to 2024. The
gapproperty (originally Grid-only) becomes Flexbox-compatible across all major browsers by Safari 14.1 (April 2021). The cleanergap: 1remsyntax replaces the older "margin on every child except the last" patterns. CSS Subgrid (2023+) lets nested grids align with parent grid tracks, useful for component-system layouts.
Praktische Workflows
- Navigation bars. A horizontal nav with logo on the left and links on the right is the canonical Flexbox use case.
display: flex; justify-content: space-between; align-items: center;on the nav container, and you're done. Addgap: 1.5remfor spacing between links. This 4-line CSS replaces what used to require floats, clearfix, and pixel-perfect margin math. - Vertical and horizontal centering. The classic "how do I center this div?" question has a Flexbox answer:
display: flex; justify-content: center; align-items: center;on the parent. Works regardless of the child's intrinsic size, regardless of the parent's height, regardless of dynamic content changes. This is the single biggest quality-of-life improvement Flexbox brought to web development. - Card-list layouts with wrapping. A row of cards that wraps to multiple rows on narrow screens:
display: flex; flex-wrap: wrap; gap: 1rem;on the container, andflex: 1 1 250pxon each card. Cards grow to fill available space, shrink down to 250px minimum, and wrap to new rows when 250px doesn't fit. Responsive design without media queries. - Form rows with labeled inputs. Forms often need labels and inputs aligned:
display: flex; gap: 0.5rem;on the row,flex: 0 0 120pxon the label (fixed 120px width),flex: 1on the input (fills remaining space). Resizing the form container keeps the label fixed and stretches the input. Easier than CSS Grid for two-column form rows. - Sticky footers. Making the footer stick to the bottom of the viewport when content is short, but follow content when it's long:
body { display: flex; flex-direction: column; min-height: 100vh; }withmain { flex: 1 }pushes the footer down. The classic "sticky footer" problem solved in three CSS declarations, replacing the negative-margin workarounds of the 2010s. - Tag and badge groups. Lists of tags, chips, or badges that should flow horizontally and wrap to new lines:
display: flex; flex-wrap: wrap; gap: 0.5rem;. Each tag sizes itself, and the container handles arrangement. Used heavily in filtering UIs, content tagging, search interfaces. Combines well with the:has()selector for state-dependent styling.
Haeufige Fallstricke
- The min-width: auto trap. Flex items have an implicit
min-width: auto(ormin-height: autofor column directions) that prevents them from shrinking below their content's intrinsic minimum size. This causesoverflow: hiddenand text-truncation patterns to fail unexpectedly inside flex containers. Fix: explicitly setmin-width: 0on the problematic flex item. This is the single most common "why is my flex layout broken?" cause. - flex-basis vs width confusion.
flex-basisis the initial size of a flex item along the main axis, before grow/shrink calculations.width(orheightfor column directions) is the regular CSS size. When both are set, flex-basis wins. The shorthandflex: 1 1 200pxsets flex-basis to 200px. For most cases, prefer flex-basis over width inside flex containers for clarity. - gap support in older browsers. The
gapproperty was originally Grid-only and arrived in Flexbox more recently: Safari 14.1 (April 2021), and earlier in Chrome/Firefox. For projects supporting older Safari (or older WebView in iOS apps), provide fallbacks using margins on children. Most modern projects can safely use gap; check your specific browser support targets. - Default flex-shrink can cause unexpected sizing. Flex items default to
flex-shrink: 1, meaning they can shrink below their declared width if the container is too narrow. To keep an element at its declared width regardless of available space, setflex-shrink: 0. Common with sidebars that should stay 250px wide even when the main content area pushes them:flex: 0 0 250pxinstead offlex-basis: 250px. - Percent flex-basis is relative to container.
flex-basis: 50%means "50% of the flex container's main-axis size." This works for typical layouts but interacts weirdly withflex-wrap: if the container itself has a percent-based main-axis size in a nested flex context, the math compounds. When in doubt, use pixel values ormin()/max()/clamp()for flex-basis instead of percentages. - IE 11 Flexbox has buggy edge cases. Internet Explorer 11 (retired June 2022) implemented Flexbox with several bugs: min-height not respected, broken nested flex containers,
flex: 1sometimes treating flex-basis as 0px instead of 0%, the "two-value flex" shorthand handled inconsistently. For projects no longer supporting IE, ignore. For legacy enterprise software, test thoroughly or use alternative layout approaches.
Datenschutz und Datenverarbeitung
CSS learning and layout tools come in two flavors: simple HTML pages running client-side JavaScript (private, fast, no setup) and cloud editors with saved projects (collaborative but with privacy trade-offs). This tool is the first kind. Your property selections, your item configurations, your generated CSS: all stay in your browser session. Refresh the page and the state is gone unless you copied the CSS first.
The privacy stakes are low here because Flexbox configurations rarely contain sensitive information. Still, the lack of analytics matters: you can experiment freely without your trial-and-error process being recorded. Particularly useful in classroom or corporate training settings where having students or trainees register accounts on third-party platforms is a friction point. The tool is a single static page with no backend, usable in any browser, including locked-down enterprise machines.
Wann Flexbox nicht zu verwenden ist
- CSS Grid for two-dimensional layouts. Flexbox is one-dimensional; if you need to align items in both rows and columns simultaneously (e.g., a magazine-style layout with mixed-size cards), CSS Grid is dramatically better suited. Use our CSS Grid Generator for that kind of work. The two work great together: Grid for page-level structure, Flexbox for component-internal arrangements.
- HTML tables for tabular data. If your data is actually a table (rows representing records, columns representing fields), use a real
<table>element with<tr>and<td>. Tables provide semantic meaning to screen readers, sortable headers, and built-in alignment. Flexbox/Grid for tables is a 2010-era antipattern; modern accessibility guidelines explicitly recommend semantic HTML tables for tabular data. - position: absolute for overlays and tooltips. Modal overlays, tooltips, dropdown menus, and similar floating UI elements work best with
position: absoluteorposition: fixedrather than Flexbox. Flex/Grid manage layout flow; absolute positioning lifts elements out of flow entirely. Combine them: Flexbox for the main page layout, absolute positioning for the modal that overlays it. - CSS Subgrid for nested alignment. When nested layouts need to align with the parent's grid (e.g., card titles all aligning across a card grid), CSS Subgrid (Firefox 71 2019, Chrome 117 2023, Safari 16 2022) is more appropriate than nested Flexbox. Subgrid lets children inherit grid tracks from the parent, ensuring perfect alignment across nested structures. Worth learning for design-system component work.
Mehr Fragen
What does the flex shorthand mean exactly?
The flex shorthand sets three properties at once: flex: <grow> <shrink> <basis>. Common values: flex: 1 (1, 1, 0%) for equal-distribution items, flex: 0 0 auto for fixed-size items, flex: 1 1 250px for items that grow/shrink from a 250px starting point. The shorthand has special initial values when only one or two values are provided; the explicit three-value form avoids surprises.
How do I make items wrap to multiple rows?
Set flex-wrap: wrap on the container. Items overflow to a new line when they don't fit. Combine with flex-basis on items to control how many fit per row: flex: 1 1 200px creates a responsive grid where items are at least 200px, grow to fill remaining space, and wrap to new rows on narrow screens. The container gap property handles spacing between wrapped rows and items.
Can I reverse the order of flex items?
Yes, multiple ways. Container-level: flex-direction: row-reverse (or column-reverse) reverses all items in order. Item-level: the order property assigns numeric weights; items with lower numbers appear first. Default order is 0; setting order: -1 on one item moves it to the front. Accessibility note: visual reordering doesn't affect tab order or screen-reader reading order, which can confuse keyboard and assistive-tech users. Use sparingly.
What is the difference between align-items and align-content?
align-items aligns items within their row (or column) along the cross axis. align-content aligns the rows (or columns) themselves within the container, only meaningful when there are multiple wrapped lines. If flex-wrap is set to nowrap (the default), align-content has no effect because there's only one line. Use align-items for single-line alignment, align-content for multi-line alignment.
How do I center a single element with Flexbox?
The classic answer: display: flex; justify-content: center; align-items: center; on the parent container. This centers the child both horizontally and vertically. For just horizontal: use justify-content: center only. For just vertical: use align-items: center only. If you need to center inside a parent of unknown height, add min-height: 100vh to the parent so it has vertical space to center within. The whole pattern replaces 20 years of CSS centering workarounds.
Why doesn't my text truncation work in a flex container?
Because of the min-width: auto default on flex items. Text-overflow: ellipsis requires the element to actually overflow its container; with the default minimum width set to the content's intrinsic size, the element never overflows. Fix: add min-width: 0 to the flex item containing the truncating text. This is the most common Flexbox bug Stack Overflow answers ever: searching "flex text-overflow ellipsis not working" returns thousands of versions of this exact answer.