EduFlow
UI Design with Figma
0%

Section 2 · Layout

Auto Layout: Direction, Gap and Padding

18 min4 min readFill in the blanks

Lesson at a glance

Turn static frames into auto layout frames that stack their children with a set flow, gap, padding and alignment, and nest them to build Steady’s habit row and list.

  1. 1The three settings that matter most
  2. 2Building the habit row
  3. 3Alignment

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

In the last lesson you built a habit row by placing an icon, a name, a streak and a check button by hand. Now change “Read” to “Read 20 pages before bed”. The name runs into the check button. Add a second line and the streak overlaps the next row. Every content change means nudging layers, and in a real app content changes every day.

Auto layout is Figma’s answer: you tell a frame how to arrange its children, and it positions them for you, every time anything changes.

The three settings that matter most

Select the habit row’s layers and press Shift+A, or click Add auto layout in the right sidebar. Figma wraps them in an auto layout frame and makes a first guess at the settings. Three of them do most of the work.

Flow is the direction children are placed in. At the time of writing, Figma offers Vertical, Horizontal and Grid. Vertical stacks children top to bottom, like the habit list. Horizontal lines them up side by side, like the inside of one row. Grid places children in rows and columns, which suits a two-dimensional layout such as the icon picker in the New habit sheet.

Gap is the space between children. It is one number for the whole frame, so every child is the same distance from the next. You can also choose automatic spacing, which at the time of writing offers Between, Around and Evenly, to distribute leftover space instead of fixing it. Use a fixed number almost always; automatic spacing is for cases like a tab bar where items spread across the width.

Padding is the space between the children and the frame’s own edges. You can set it on all sides at once, horizontal and vertical separately, or per side.

Building the habit row

Here is the row as nested auto layout frames. Each frame has one job.

Text
Habit row        Horizontal · gap 12 · padding 12 top/bottom, 16 left/right · align center
├─ Icon          32 × 32
├─ Text stack    Vertical · gap 4
│  ├─ Habit name   Headline 17/24
│  └─ Streak       Caption 13/16
└─ Check button  32 × 32 circle

The text stack is its own vertical frame because the name and streak are a group (Lesson 1.2: small gap inside, bigger gap outside). The row is horizontal because icon, text and button sit side by side. The 4 px inside the text stack is smaller than the 12 px between row elements, which is smaller than the space between rows. Proximity is now built into the structure, not maintained by hand.

A habit row frame with 16 pixel left and right padding and 12 pixel top and bottom padding. Inside, an icon, a text stack and a check button are separated by 12 pixel gaps. The text stack holds the name and streak with a 4 pixel gap. 16 16 Icon 12 Read 20 pages 12-day streak gap 4 12 padding 12 top padding 12 bottom
Anatomy of the habit row: padding on the outside, gap between children

Now stack rows. Select all the rows and press Shift+A again: Figma wraps them in a vertical frame, the Habit list, with an 8 px gap. Wrap the progress block and list in a vertical frame with a 24 px gap, then wrap the header and that frame in one more vertical frame with 20 px horizontal padding and a 32 px gap. Two levels of gap give you the stepped spacing from Lesson 1.2, and the whole Today screen is now structured by auto layout. Change any name, add a sixth habit or delete one, and everything below moves to make room.

Alignment

Each auto layout frame also controls how its children line up across the flow. In a horizontal row, you choose whether children sit at the top, center or bottom of the row; in a vertical stack, whether they hug the left, center or right. The habit row uses center alignment so the icon and check button line up with the middle of the text, whether the name is one line or two.

For rows of text with different sizes, horizontal frames also offer baseline alignment at the time of writing, which lines up the bottoms of the letters instead of the boxes. It is ideal for a label and a value side by side, such as “Streak” and “12 days”.

You have the habit row stacking correctly. What it does not do yet is stretch to fill the screen width or let long names wrap at the right place. That is resizing, the subject of the next lesson.

Key takeaways

  • Auto layout makes a frame arrange its children for you, so changing content never means nudging layers by hand again.
  • Flow sets the direction (vertical, horizontal or grid), gap sets the space between children, and padding sets the space between the children and the frame’s edges.
  • Spacing belongs to the parent frame, never to spacer rectangles or offsets on the children.
  • Real components are nested auto layout frames, such as a horizontal row that contains a vertical text stack.
  • Most auto layout bugs come from settings on the wrong level of nesting, so check the parent before you blame the child.

Further reading

Check your understanding

4 questions

Question 1 of 4

You change a habit name from “Run” to “Run 5 km before work” inside an auto layout habit row. What happens to the check button on the right?

Question 2 of 4

The text stack inside a habit row has 4 px gap, and the row has 16 px left padding. A designer adds a 16 px empty rectangle before the icon to push it right. What is wrong?

Question 3 of 4

Which structure best describes Steady’s habit row?

Question 4 of 4

Inside a horizontal habit row, the icon sits at the top while the text and check button are centered. Where do you fix it?

Practice

Fill in the blanks

Set up the frequency chips

The New habit sheet has a row of frequency chips: Daily, Weekdays, Weekends, Custom. Each chip is a 16 × 16 icon followed by its label. From the developer’s redline:

  • In each chip, the icon and label sit 4 px apart and are centered on each other vertically.
  • The chip’s content sits 12 px from its left and right edges and 6 px from its top and bottom edges.
  • The chips sit side by side, 8 px apart.

Fill in the auto layout settings for one chip and for the row that holds all four. Use the names Figma shows (Vertical, Horizontal or Grid for flow; Top, Center or Bottom for alignment) and numbers in px.

Chip (auto layout) Flow: Gap between items: Padding left/right: Padding top/bottom: Align children: Frequency chips (auto layout) Flow: Gap between items: