Skip to main content
RapidDev - Software Development Agency
webflow-tutorials

Webflow Flexbox and Grid: Alignment, Spacing, and Centering

Set Display: Flex or Display: Grid on a container in Style Panel > Layout to control how child elements arrange themselves. For centering: Flex with Justify: Center and Align: Center centers any element horizontally and vertically. For multi-column layouts: Grid with column templates (1fr 1fr) creates equal columns automatically. Both are fully visual in Webflow — no CSS code required.

What you'll learn

  • Enable Flexbox on a container and control direction, justify, align, wrap, and gap from the Layout section
  • Center elements both horizontally and vertically using the Flex alignment controls
  • Enable CSS Grid, define column and row templates, and control item placement
  • Use auto-fit and minmax column templates for responsive grids without breakpoint overrides
  • Know when to use Flex (1D single axis) vs Grid (2D multi-axis) for different layout problems
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate11 min read25-35 minAll Webflow plans (custom code requires Basic plan or above)March 2026RapidDev Engineering Team
TL;DR

Set Display: Flex or Display: Grid on a container in Style Panel > Layout to control how child elements arrange themselves. For centering: Flex with Justify: Center and Align: Center centers any element horizontally and vertically. For multi-column layouts: Grid with column templates (1fr 1fr) creates equal columns automatically. Both are fully visual in Webflow — no CSS code required.

Webflow Flexbox and Grid: Alignment, Spacing, and Centering

Flexbox and Grid are the two layout engines behind every modern Webflow design. Flexbox arranges children in a single axis (row or column) with flexible sizing and alignment. Grid arranges children in a two-dimensional system (rows AND columns) with template-based tracks. This tutorial covers both systems in Webflow's visual editor — how to enable them, control direction and alignment, manage gap spacing, center elements in both axes, and choose between Flex and Grid for different layout patterns. This is focused on the container layout tools, which are distinct from positioning (z-index stacking) or hero section patterns.

Prerequisites

  • A Webflow project with a container Div Block and some child elements
  • Familiarity with the Style Panel (S) and Navigator (Z)
  • Understanding that layout is set on the PARENT container, not the children

Step-by-step guide

1

Enable Flexbox on a container

Select a parent Div Block that contains child elements you want to arrange. Open the Style Panel (S). The first section is Layout. Click 'Flex' in the Display row (Block, Flex, Grid, Inline Block, Inline, None). The Style Panel immediately expands to show Flex controls: Direction (row icons and column icons), Justify (main axis distribution icons), Align (cross axis distribution icons), Wrap, and Gap. By default, children line up in a Row with no wrapping. The Flex container shows an interactive box model diagram — clicking the alignment buttons applies standard Flexbox values without needing to memorize CSS property names.

Expected result: Child elements arrange in a horizontal row (default Flex row direction). The Style Panel shows the full Flex control set.

2

Center an element horizontally and vertically with Flex

The most common use case for Flex is centering. Select the parent container. Enable Flex. Set Direction to Row. Click Justify to the center option (the icon with items centered on the horizontal axis — this sets justify-content: center). Click Align to the center option (the icon with items centered on the vertical axis — this sets align-items: center). Your child element(s) are now perfectly centered in both axes. For this to work, the parent container needs a defined Height — if Height is Auto, the container collapses to the content height and 'vertical centering' has no space to work with. Set Height: 500px or Height: 100vh.

Expected result: The child element appears perfectly centered both horizontally and vertically within the parent container.

3

Control Flex direction, wrapping, and gap

Set Direction to Column to stack children vertically (like a vertical navigation or card stack). Wrap determines what happens when children overflow: 'No Wrap' (default) — children shrink or overflow; 'Wrap' — children wrap to the next line; 'Wrap Reverse' — wrap, but from bottom to top. Gap controls the space between children (replaces manual margins): set Gap to 24px to add 24px between each child. You can also set independent horizontal and vertical gap using the Gap controls — click the gap input to expand separate X and Y gap fields. Flex children don't need margin between them when Gap is set — the container handles all spacing.

Expected result: A two-up (two column) card layout where each card is 50% width wraps naturally to a single column when the container is less than the combined minimum width.

4

Control individual child alignment with Flex child settings

While Flex controls are set on the parent, you can override alignment for individual children. Select a child element inside a Flex container. The Style Panel > Layout section shows 'Flex Child' controls instead of the parent Flex controls. Here you'll find: Align Self (override the parent's align-items for this child only — useful for a 'featured' card that stretches taller), Order (change the visual order of this child without changing HTML structure — useful for reordering on mobile), and Flex controls for how this child sizes itself (Flex Grow, Flex Shrink, Flex Basis). Set a child to Flex Grow: 1 to make it fill remaining space in the row.

Expected result: Individual child elements have overridden alignment or ordering as specified, while siblings follow the parent Flex rules.

5

Enable CSS Grid and define column templates

Select a container Div Block. In Style Panel > Layout > Display, click 'Grid'. The Style Panel shows Grid controls: Columns template, Rows template, Column Gap, Row Gap, and cell alignment options. For a basic three-column layout: click the Columns input and set it to '1fr 1fr 1fr' (three equal-width columns, each taking one fraction of available space). For a two-column layout with a wider main column: '2fr 1fr'. For automatic responsive columns that fit as many as possible: use the Custom Properties section at the bottom of the Style Panel and add property 'grid-template-columns' with value 'repeat(auto-fit, minmax(280px, 1fr))'. This is the auto-fit minmax pattern that creates a responsive grid without any breakpoint overrides.

Expected result: Child elements arrange in the defined grid columns. A three-column grid shows three items per row, automatically wrapping to new rows for additional items.

6

Control Grid gap and cell alignment

In the Grid layout controls, set Column Gap (horizontal space between columns) and Row Gap (vertical space between rows) independently. For a card grid, a common value is 24px for both. For alignment within cells, Webflow shows Justify Items (horizontal alignment of cell content) and Align Items (vertical alignment). Set both to Center to center all cell content. For individual grid items, select the child element and use Justify Self and Align Self in the Flex/Grid Child section of the Layout panel to override cell-level alignment. To span a grid item across multiple columns: select the child > Custom Properties > add 'grid-column' with value 'span 2' (spans 2 columns).

Expected result: A card grid with 24px gaps between columns and rows displays with properly aligned cell content.

7

Choose between Flex and Grid for your layout

The common guideline: use Flex for one-dimensional layouts (a row of buttons, a vertical stack, a horizontal nav), and use Grid for two-dimensional layouts (card grids, dashboard layouts, image galleries). In practice, Webflow makes this easy to try either way. Flex with wrap = simple equal-width column grid. Grid = precise control over column widths, spanning, and placement. Specific scenarios where Grid wins: you need a masonry-like layout; you want a card to span two columns; you need precise row heights. Where Flex wins: centering a single element; navigation bars; any layout that should grow/shrink based on content size. Neither is wrong — use whichever produces the layout you need with fewer overrides.

Expected result: You can identify which layout tool to reach for given a specific design problem and implement it through the Style Panel without trial-and-error guessing.

8

Build a responsive auto-fit card grid

Create a parent Div Block and set Display: Grid. In the Style Panel > Layout, you'll see the Columns template input. For a truly responsive auto-fit grid, the native Webflow grid UI doesn't expose the auto-fit/minmax pattern — you need Custom Properties. Scroll to the bottom of the Style Panel > Custom Properties section. Add property: 'grid-template-columns', value: 'repeat(auto-fit, minmax(280px, 1fr))'. Set Column Gap and Row Gap to 24px in the regular Grid controls. Now add 6 child Div Blocks (your cards) inside. On a wide screen they'll show 3-4 per row; on narrow screens they'll automatically reduce to 2 and then 1 column without any breakpoint overrides.

Expected result: A card grid that automatically adjusts its column count based on available space — no manual breakpoint overrides needed for basic responsiveness.

Complete working example

Visual Steps Summary
1FLEXBOX & GRID VISUAL STEPS SUMMARY
2
3FLEX SETUP:
4 Parent Div > Style Panel > Layout > Display: Flex
5 Direction: Row (horizontal) or Column (vertical)
6 Justify (main axis): flex-start / center / flex-end / space-between / space-around
7 Align (cross axis): flex-start / center / flex-end / stretch
8 Wrap: No Wrap / Wrap / Wrap Reverse
9 Gap: set horizontal + vertical gap between children
10
11CENTERING SHORTCUT:
12 Display: Flex > Direction: Row > Justify: Center > Align: Center
13 (Requires parent to have a defined Height)
14
15GRID SETUP:
16 Parent Div > Layout > Display: Grid
17 Columns template: '1fr 1fr 1fr' = three equal columns
18 Column Gap + Row Gap: set spacing between cells
19
20AUTO-FIT GRID (Custom Properties at bottom of Style Panel):
21 Property: grid-template-columns
22 Value: repeat(auto-fit, minmax(280px, 1fr))
23 = Responsive grid, no breakpoint overrides needed
24
25FLEX CHILD CONTROLS (select child element):
26 Align Self: override parent's align-items for this child
27 Order: reorder visually without changing HTML
28 Flex Grow: fill remaining space
29
30FLEX vs GRID:
31 Flex = 1D (row OR column) navigation, centering, button groups
32 Grid = 2D (rows AND columns) card grids, page templates, image galleries

Common mistakes

Why it's a problem: Flex centering doesn't work — elements aren't centered vertically

How to avoid: Flex vertical centering (Align: Center) requires the parent container to have a defined Height. If Height is Auto, the container is exactly as tall as its content, so there's no space to 'center within'. Select the parent container and set a Height: 400px, 100vh, or any fixed value in Style Panel > Size. Then the Align: Center will visibly move the child to the vertical middle.

Why it's a problem: I set Display: Flex on an element but the children still stack vertically

How to avoid: Flex row direction is the default, but check that the Flex children don't have Width: 100% set on them — a 100% width child in Flex row will take the full width and push siblings to new lines even without Wrap. Select each child and check Width in the Style Panel. Change to Auto or a smaller percentage value to let them sit side-by-side.

Why it's a problem: Grid columns collapse on Mobile even though I set them to auto-fit

How to avoid: If using auto-fit with a high minimum (e.g., minmax(400px, 1fr)) and screen width is less than 400px + gap, columns collapse to one. Reduce the minimum value in minmax() to something that fits on mobile (e.g., minmax(240px, 1fr)). Alternatively, set a breakpoint-specific grid-template-columns override at Mobile Portrait: '1fr' to force single-column layout.

Why it's a problem: Flex child elements are different heights and the layout looks uneven

How to avoid: Set the Flex parent's Align to 'Stretch' (Style Panel > Layout > Align > Stretch icon) so all children stretch to the same height. For cards, also set the card content to use Flex column with Justify: space-between so internal content (title, description, CTA) distributes evenly regardless of content length.

Best practices

  • Set layout properties (Flex, Grid) on the parent container, not on the children. A common mistake is selecting a child and wondering why Flex controls aren't changing the layout.
  • Use Gap instead of adding margins to individual children — Gap is more maintainable, applies evenly, and doesn't affect the outer edges of the container.
  • For responsive card grids, use the CSS Grid auto-fit minmax pattern via Custom Properties instead of breakpoint-specific column count overrides — it handles responsiveness automatically.
  • Always give Flex containers a defined Height when you need vertical centering — without a fixed height, the container is only as tall as its content and 'centered' means the same as 'default'.
  • Use Flex child Order at mobile breakpoints to reorder elements without changing HTML structure — this is the cleanest way to show image-first on mobile when the Desktop has image-last.
  • Test Flex layouts with more content than expected — a Flex row with 'No Wrap' and 7 items instead of 3 will either overflow or squeeze items uncomfortably. Set Wrap: Wrap if item counts can vary.

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I'm using Webflow and I need to understand when to use Flexbox versus CSS Grid for my layouts. I have a card grid where I want 3 cards per row on Desktop that automatically reduces to 2 on Tablet and 1 on Mobile. I also need to center a CTA button both horizontally and vertically inside a full-height section. Walk me through the exact Webflow Style Panel settings for both of these, and explain the auto-fit minmax approach for the card grid.

Webflow Prompt

Set up the card section in this Webflow project as a responsive Grid using auto-fit minmax(280px, 1fr) with 24px gap. The individual card elements should use Flex column layout with space-between justify so the CTA button always sits at the bottom regardless of card content length. Apply these settings using the Style Panel.

Frequently asked questions

How do I center a button both horizontally and vertically in Webflow?

Select the parent container (the section or div that wraps the button). In Style Panel > Layout, set Display: Flex. Set Justify to Center (horizontal axis center). Set Align to Center (vertical axis center). Set the parent container's Height to something defined — 100vh for a full-screen section, or a fixed pixel value. The button will then be perfectly centered in both axes within that container.

What does 1fr mean in Webflow Grid column templates?

1fr means 'one fraction of the available space'. It's a flexible unit that divides the container's available width (after subtracting gaps) equally. '1fr 1fr 1fr' = three equal columns. '2fr 1fr' = the first column gets twice the space of the second. Fr units are better than percentages for grid columns because they automatically account for the gap spacing — you don't need to calculate '33% - 8px' to get equal columns with gaps.

Should I use Flexbox or Grid for a card layout in Webflow?

Both work, but they have different strengths. Flex with Wrap is simpler for uniform card grids where all cards are the same width. Grid gives you more control: you can span cards across columns, set independent row heights, and use the auto-fit minmax pattern for automatic responsiveness. For a straightforward equal-width card grid, either works. For complex layouts (featured card spanning 2 columns, variable row heights), use Grid.

Why does my Flex layout look correct in the Designer but children don't have equal heights in Preview?

Flex Align: Stretch (the default) makes children equal height, but if your cards have a fixed height set in their own styles, they won't stretch. Check each card's Style Panel > Size > Height. If Height is set to a fixed value (e.g., 300px), that overrides the Flex stretch. Set card Height to Auto and control the minimum height if needed, so Flex stretch can make them equal. Alternatively, set the Flex parent Align: Stretch to explicitly enforce equal heights.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.