Web Design & UI/UX10 min read

Hug vs Fill in Figma Auto Layout: When to Use Each

Hug when the box should follow its content, Fill when it should follow its parent, Fixed when it never resizes. Each one built and selected, three mistakes side by side, and a table for twelve common layers.

By Boone
XLinkedIn
Hug vs Fill in Figma Auto Layout: When to Use Each

Every layer in a Figma auto layout frame has a width and a height setting, and most resizing bugs start with the wrong one. Below: the question that decides it, each option built and selected, three mistakes side by side, a table for twelve common layers and what each setting becomes in code.

The one question: what should the box follow?

Ask what should decide the size of the layer. If it is the words or the icons inside it, the box follows its content: Hug. If it is the space it sits in, the box follows its parent: Fill. If it is neither, because the thing is the same size on every screen, the box follows nothing: Fixed.

Figma's own definitions draw the same line. Hug contents "resizes based on its child objects", Fill container "fills all available space", and Fixed means the size "stays fixed". You set each one separately for width and for height, from the W and H menus in the right panel.

Hug: the box follows its content

Three black buttons reading Buy, Add to Cart and In den Warenkorb, each a different width and each selected with a blue box tagged Hug × 44, and below them three colored tags reading New, Free returns and Only 2 left, each tagged Hug × 28

A Hug frame stays as small as its children plus its padding. The three buttons above share one component: 24 of padding on each side, 44 high, a 16 px label. Only the words change, and each button takes exactly the width its words need. Hug is right when:

  • The box should follow its content. A button is as wide as its label, a tag as wide as its word.
  • It is a button, a tag or a badge. Small pieces that sit in a row next to each other and should never stretch.
  • The words may get longer in another language. "Add to Cart" becomes "In den Warenkorb" in German, and the button grows with it instead of breaking.

Hug works only on auto layout frames. Text layers have their own resizing, where Auto width does the same job. To set Hug fast, double-click the edge of the selected frame.

Where Hug fails: anything that has to line up with the edges of its column. A box that only knows its own content cannot know how wide the screen is.

Fill: the box follows its parent

The same white column shown twice, first 260 wide and then 520 wide, each with a Search places input, a Rio Terrace stay row at 118 dollars a night and a black Book Now button, where the input and the button are selected and tagged Fill × 44 and stretch to the edges of both columns

A Fill layer takes all the space its parent frame gives it, minus padding and gaps. Above, the same column sits in a parent 260 wide and then one 520 wide. Nothing inside was edited: the input, the stay row and the button reach the edges both times. Fill is right when:

  • The box should follow its parent. The column decides the width, not the words inside.
  • It is an input or a card in a column. Search fields, form fields, list rows and full-width buttons all line up on the same two edges.
  • It has to stretch from phone to desktop. One component, every screen width, no second version to keep in sync.

Fill works only on children of an auto layout frame, never on a top-level frame. To set it fast, hold Option (Alt on Windows) and double-click the edge.

Where Fill fails: wide screens. A Fill button on a 1,200 wide desktop form is a 1,200 wide button. That is what max width is for (mistake 3 below).

Fixed: the third option

On the left, an avatar tagged 40 × 40 and a heart icon tagged 24 × 24. On the right, a Figma auto layout panel with the width set to Hug and its open menu listing Fixed width, Hug contents with a check, Fill container, Add min width and Add max width

Fixed keeps a layer the same size whatever happens around it. Use it for the things that never resize: icons, avatars, a logo, a thumbnail of a set size. Fixed is also where Figma puts you without asking: drag a frame's edge or type a number into the width field, and that axis switches to Fixed. A button that hugged yesterday and has an odd width today usually had its width typed in by hand.

Mistake 1: a button with a fixed width

Wrong: fixed at 140

An Add to Cart button fixed at 140 by 44 that fits, and the same button in German, In den Warenkorb, also fixed at 140, with the end of the word running past the right edge in red

Right: both hug

The same two buttons set to Hug, Add to Cart and the wider In den Warenkorb, each with even padding on both sides

At 140 wide, the English button looks perfect, so nobody notices the width was typed in. Then the German build arrives. "In den Warenkorb" needs about 184 at the same size and padding, and the last letters run out of the button. On the right, both hug: each button is as wide as its label plus 24 on each side, in every language.

Mistake 2: an input that hugs

Wrong: the input hugs

A Search places input that ends right after its placeholder text, selected in red and tagged Hug × 44, above a full-width Book Now button

Right: the input fills

The same input stretched to the edges of the column, tagged Fill × 44, lined up with the Book Now button below it

This one runs the other way. An input is a frame with a placeholder inside, so Hug wraps it around the words "Search places" and stops. The box now says the field is short, its right edge floats in the middle of the column, and it lines up with nothing. An input follows the column, not the placeholder: set it to Fill, and its edges meet the button's.

Mistake 3: Fill with no max width

Wrong: Fill with no limit

A Sign in form on a wide screen where the email field and the Continue button stretch across the whole column, the button selected in red and tagged Fill × 44

Right: Fill with max width 400

The same form where the email field and the Continue button stop at 400 wide, tagged Fill × 44 · max W 400

Fill is right for a form, and on a phone this form is fine. On a desktop column it turns into a bar the eye has to travel across.

Keep Fill and add a limit: in the width menu, Add max width, then type 400. The field still stretches on small screens and stops growing on big ones. Add min width works the same way from the other side, useful for a button that should never get narrower than a thumb.

Fill inside Hug: what the parent does

A child set to Fill needs a parent with a size to fill. So when any child of an auto layout frame is set to Fill, Figma stops the parent hugging on that axis and sets it to Fixed. If a card suddenly stops growing with its text, look for a child someone set to Fill.

The working order from the outside in: the screen is Fixed (it is the device width), the columns and cards inside it Fill, and the small pieces in them, buttons in a row, tags and badges, Hug.

Hug, fill or fixed: a decision table

Here are twelve common layers and the width each one needs.

LayerWidthWhy
Button in a row of buttonsHugIts label decides the width
Full-width button at the bottom of a phone screenFillIt lines up with the column edges
Tag, chip or badgeHugOne word, never stretched
Text input or search fieldFillIt follows the form column, not the placeholder
Form on desktopFill + max widthStretches on phones, stops at a reading width
Card in a single column listFillEvery card shares the same two edges
Card in a horizontal scroll rowFixedThe row needs equal cards that do not squeeze
IconFixedAlways the same size
AvatarFixedAlways the same size
TooltipHug + max widthGrows with short text, wraps long text
Navigation barFillSpans the screen
Screen or top-level frameFixedFill is not available at the top level

Height mostly follows a simpler rule: Hug, so a component grows when its text wraps onto a second line, and Fixed only for things like icons and a bar with a set height.

Hug and fill in code

Auto layout works like CSS flexbox, so each setting has a close match a developer can type.

FigmaCSSWhat it does
Hug contentswidth: fit-contentAs wide as the content, never wider than the container
Fill container, along the rowflex-grow: 1Takes the free space left in the row
Fill container, across the columnalign-self: stretchStretches to the column's width
Fixedwidth: 24pxA set size
Min and max widthmin-width, max-widthLimits on top of any of the above
css
.button { width: fit-content; padding: 0 24px; height: 44px; } .search-input { align-self: stretch; } .form { width: 100%; max-width: 400px; } .icon { width: 24px; height: 24px; flex-shrink: 0; }

The flex-shrink: 0 on the icon matters: without it, a crowded row can still squeeze a 24 px icon. For handing the rest of a file over, read design handoff from Figma to dev. For the spacing values themselves, read Figma variables architecture.

FAQ

What is the difference between hug and fill in Figma?

Hug contents makes a frame as small as its children plus its padding, so it follows its content. Fill container makes a layer take all the space its parent gives it, so it follows its parent.

When should I use hug contents?

Use Hug for buttons, tags, badges and anything whose size should come from its own words, especially labels that get longer when translated.

When should I use fill container?

Use Fill for inputs, cards and buttons in a column, and anything that has to stretch from a phone screen to a desktop one. It only works on layers inside an auto layout frame.

Why did my Figma frame stop hugging?

Either a width was typed in or dragged by hand, which sets it to Fixed, or one of its children was set to Fill, which makes the parent Fixed on that axis. Set the child back or give the parent a fixed size on purpose.

What does fill container mean in CSS?

Along a flex row it is closest to flex-grow: 1. Across a column it is align-self: stretch. Hug is closest to width: fit-content.

Sources

  • Guide to auto layout, Figma Help Center: hug contents, fill container, fixed width and height, min and max dimensions, the double-click and Option double-click shortcuts, typing a width sets Fixed, a Fill child makes its parent Fixed, Fill not available on top-level frames, text resizing.
  • fit-content, flex-grow and align-self, MDN Web Docs.
  • The buttons, tags, Rio Terrace row, sign-in form and every size on the screens above are invented for the demo and drawn for this page. Button widths (about 78 for Buy, 137 for Add to Cart, 184 for In den Warenkorb) are measured from Inter SemiBold at 16 px with 24 of padding on each side. "In den Warenkorb" is ordinary German for Add to Cart.
  • First published as a carousel on UX Brainy.

More from Brainy Papers

Keep reading