Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 36 ยท Auto Layout and Constraints

Auto Layout Basics: Direction, Spacing and Padding

Learn Figma auto layout from scratch: add it with Shift+A, choose direction, gap, padding and alignment, and see the arithmetic behind it with a runnable layout engine stand-in.

In the first design lesson you positioned every layer by typing X and Y values. That works for a card, but a real app has lists that grow, buttons whose labels change, and screens that must adapt. Auto layout solves this: you describe the rules (direction, spacing, padding) and Figma calculates the positions. It is the single most important feature in modern Figma, and the closest thing it has to CSS Flexbox.

Adding auto layout

  1. Select one or more layers (or a frame).
  2. Press Shift+A, or click the + next to Auto layout in the right panel.
  3. Figma wraps your selection in a frame (or converts the selected frame) and arranges the children in a row or column.

Select the container and a new section appears in the right panel with all the settings. Layers inside an auto layout frame are laid out in the order they appear in the Layers panel; drag a child on the canvas to reorder it, and a blue line shows where it will land.

Shift+A also removes auto layout from a selected container when you press it again with the frame selected: the children keep their current positions.

Direction

Auto layout arranges children in one of these ways:

  • Vertical: a column, from top to bottom.
  • Horizontal: a row, from left to right.
  • Wrap (a third option, in newer versions): a row that wraps to a new line when full, like a flex-wrap.
  • Grid (newer versions): rows and columns of equal cells.

Think of the main axis as the direction in which items follow one another. Horizontal means the main axis points right.

Gap (spacing between items)

Spacing between items (often called gap) is the distance between neighbouring children along the main axis. Type a number, such as 16. There is also an Auto option, in which the gap becomes flexible so that items spread out and the first and last touch the edges ("space between" in CSS terms).

Padding

Padding is the space between the container's edge and its children. You can set one value for all sides, or two values (horizontal and vertical), or four (top, right, bottom, left). A button with a label usually uses horizontal padding 24 and vertical padding 12.

Auto layout settings

Direction Row or column
Gap Space between items
Padding Space inside the edge
Alignment Where items sit

Rules instead of manual positions

1 / 2

Alignment

The 3 by 3 alignment grid in the panel decides where items sit on both axes. For a vertical stack, the horizontal choice (left, center, right) says whether children line up on the left edge or center, and the vertical choice matters when the container is taller than the content. Pressing the middle square centers everything. Alignment is the thing you change when a button label looks off-center.

Why it matters

Imagine a list of five rows and you add a sixth. With manual positions, you shift every layer below. With auto layout, the container grows and nothing needs to move. Delete or hide a layer and the gap closes by itself.

Build a button

  1. Draw a text layer Continue.
  2. Select it and press Shift+A: Figma creates a frame around it.
  3. Set horizontal padding 24, vertical padding 12.
  4. Give the frame a fill, a corner radius and rename it Button.

Now edit the text: the button resizes with the label, because the container hugs its contents (covered in Hug, Fill and Fixed Sizing).

How the layout engine works: a stand-in

This stand-in (plain Python, not Figma's code) computes the positions of children in a horizontal auto layout, given padding and gap. It shows the arithmetic Figma does for you.

Python Stand-in: horizontal auto layout

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The container is 24 + 24 + 8 + 80 + 24 = 160 px wide and 12 + 24 + 12 = 48 px tall: the same math you would do when the content changes.

A vertical stack and recalculation

Add or remove a child and everything is recomputed. This second stand-in does it for a vertical list.

Python Stand-in: list that grows

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The height changes from 192 to 248 and back to 192 without any manual moving, which is the value auto layout gives you in Figma.

Absolute position

Sometimes one child should ignore the layout, such as a notification badge pinned to the corner of an avatar. Select the child and choose Ignore auto layout (the icon with a small arrow in the Layout section, or Absolute position). It then floats freely and can use constraints.

Common mistakes

  • Putting auto layout on the whole screen when only a section needs it.
  • Using spacers (empty rectangles) instead of gap and padding.
  • Forgetting that order in the Layers panel is the order on canvas; reorder in either place.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which shortcut adds auto layout?

    Shift+A adds auto layout to a selection or frame.
  2. 2. What is padding in auto layout?

    Padding is inside the frame; gap is between children.
  3. 3. A row has padding 16 on each side, two 40 px children and gap 8. What is the width?

    16 + 40 + 8 + 40 + 16 = 120.
  4. 4. How do you let one child ignore the layout?

    Absolute position removes it from the flow while it stays inside the frame.

Summary

  • Shift+A adds auto layout; the container arranges children by direction, gap and padding.
  • Alignment sets where items sit; Auto gap spreads items out.
  • Lists and buttons resize themselves when content changes.
  • Use absolute position for badges and overlays.

Next: Hug, Fill and Fixed Sizing