Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 36 ยท Auto Layout and Constraints

Constraints and Responsive Resizing in Figma

Learn how Figma constraints control layers when a frame is resized: left, right, center, scale, top and bottom, how they relate to auto layout, with a runnable stand-in.

When you resize a frame, what should happen to its children? Should the logo stay put in the top left, should a button stay glued to the bottom right, should a banner stretch to full width? Figma answers with constraints: per-layer rules that say how a child is pinned inside its parent frame. Constraints and auto layout are the two tools for responsive design; this lesson covers constraints, and ends with how to choose between them.

Where to find them

Select a layer inside a frame. In the right panel, the Constraints section shows a small box diagram with two drop-downs: one for horizontal and one for vertical. You can also click the lines in the diagram.

Constraints are only meaningful for children of a frame (not groups), and they take effect when the parent frame is resized: drag its handles, change its width, or switch the device preset. They do nothing while you simply move layers around.

Layers inside auto layout frames do not use constraints, unless they are set to ignore auto layout (absolute position). In that case, they can be pinned just like in any other frame.

The horizontal options

  • Left: the distance from the left edge stays the same. The layer stays pinned to the left.
  • Right: the distance from the right edge stays the same.
  • Left & Right: both distances stay the same, so the layer stretches when the frame widens.
  • Center: the layer stays centered horizontally, at a fixed offset from the center.
  • Scale: the layer's position and size scale in proportion with the frame.

The vertical options

They mirror the horizontal ones: Top, Bottom, Top & Bottom (stretch), Center and Scale.

Constraint types

Left / Top Pinned to that edge
Right / Bottom Pinned to the far edge
Both edges Stretches with the frame
Center / Scale Stays centered or scales

Applies when the parent resizes

1 / 2

What happens in practice

Say a frame is 400 px wide and contains a 100 px wide button positioned 20 px from the left, and then the frame becomes 600 px wide.

Constraint New position New width
Left 20 px from the left 100
Right 20 + 200 = 220 px from the left (distance to the right edge unchanged) 100
Left & Right 20 300 (stretches by 200)
Center moves right by 100 100
Scale 30 px from left 150

You can predict every result with simple arithmetic, and the stand-in below does exactly that.

A constraint calculator (stand-in)

This stand-in is plain Python, not Figma code, but it applies the same rules to a child rectangle when the parent's width changes.

Python Stand-in: resolve horizontal constraints

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 table above and this output agree: for Left & Right the width grows by the 200 px the frame gained.

Resizing a whole screen

Think of the typical mobile screen: a header stuck to the top and stretching across (Left & Right, Top), a floating button pinned bottom-right (Right, Bottom) and a content area that stretches both ways. Test your design by selecting the frame and dragging it narrower or wider, or switch the frame's size to another device preset. If something jumps or overlaps, adjust its constraints.

Python Stand-in: test a screen at three widths

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 floating button's right gap stays 16 at every width, while the banner keeps 16 px margins on both sides: precisely what the constraints promise.

Scale versus the others

Scale is rarely the right answer for interfaces, because text and buttons then change size. It suits illustrations, backgrounds and decorative shapes whose proportions should stay fixed relative to the frame. In UI design you generally choose pinned edges, centers and stretching, and rely on auto layout for everything that flows.

Constraints or auto layout?

  • Use auto layout for content that flows in rows or columns and changes length: lists, forms, buttons, cards, toolbars.
  • Use constraints for fixed relationships to the edges of a frame: a close button in a corner, a floating action button, a full-bleed background, or a logo in a fixed spot.
  • Combine them: an auto layout screen with an absolute-positioned (ignore auto layout) floating button, pinned with constraints.

Developers translate constraints loosely into CSS positioning: pinned edges become top, right, bottom or left, centering becomes margin: auto or transforms, stretching becomes left plus right. Auto layout translates to Flexbox. Knowing both makes your handoff clearer.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. When do constraints take effect?

    Constraints describe how a child follows its parent frame's changes.
  2. 2. Which constraint makes a layer stretch as the frame widens?

    Pinned to both edges means the width changes with the frame.
  3. 3. A 100 px wide layer at x=20, constraint Right. The frame grows from 400 to 600. New x?

    The distance to the right edge is preserved, so the layer moves right by 200.
  4. 4. Where are constraints available?

    They apply to children of a frame, not groups.

Summary

  • Constraints (left, right, both, center, scale; top, bottom, both, center, scale) pin a child to its parent frame.
  • They apply when the parent is resized, not when you drag layers.
  • Auto layout handles flowing content; constraints handle fixed relationships to edges.
  • Test your design by resizing the frame to several widths.

Next: Nested Auto Layout, Wrap and Real Layouts