Figma: frames, auto layout, styles, variables and components¶
Exercise figma-auto-layout-annex.pdf · PDF
Open any app on your phone and count the buttons. Dozens. Now imagine your boss says: "Make every button a bit rounder and change the red to a darker red." Would you redraw them one by one, across 40 screens? Professional designers never do. They build the screen once from reusable pieces, change the piece, and every copy updates by itself.
That is what this page is about. Figma is the design tool you will use all year to draw your project's screens before you code them. Five ideas make it powerful: frames, auto layout, styles, variables and components. Learn them now and your prototype turns into code much more easily in Unit 2.
What you will learn
- What a frame is, and why you should use it instead of a group
- How auto layout makes a button grow with its text, with no manual resizing
- How styles and variables give every colour and font one single source of truth
- How modes switch a whole design from light to dark in one click
- What components, instances and variants are, and why a change to the main component reaches every copy
- The trap: why detaching an instance breaks the link for good
The LEGO factory¶
Keep one picture in your head for the whole page: Figma is a LEGO factory.
| Figma idea | In the LEGO factory |
|---|---|
| Frame | A box with walls: a fixed size, a colour, and bricks inside |
| Auto layout | A smart tray that spaces the bricks for you and grows when you add one |
| Style / variable | The official colour chart: "Bright Red" is defined once and used everywhere |
| Mode | A second column in the chart: the night version of every colour |
| Component | The mould: every brick made from it is identical |
| Instance | One brick made from the mould |
Frames: the box every screen starts in¶
A frame is a container layer: it holds other layers (shapes, images, text) and has its own size and style.
Every screen you design starts as a frame. Press F (or A), then pick a preset from the right panel: Phone, Tablet, Desktop, Watch... Figma sets the right size for that device.
Figma also has groups (Cmd+G / Ctrl+G). A group is just a rubber band around some layers. They look alike, but they behave very differently:
| Frame | Group | |
|---|---|---|
| Size | Has its own size. You decide it | Wraps its contents: it grows and shrinks as you move the layers inside |
| Fill, stroke, effects | Yes, like a rectangle | No |
| Clip content (hide what sticks out) | Yes | No |
| Constraints for the layers inside | Yes | No: constraints look for the nearest parent frame |
| Auto layout | Yes | No |
In the factory: a frame is a box with walls. A group is a rubber band around some bricks.
Careful: frames, not groups
Beginners group everything because Cmd+G is easy to remember. Then the screen does not resize properly and auto layout is missing. Rule of thumb: use a frame for anything that is part of the interface (a screen, a card, a button). Use a group only to move a few loose layers together. To turn a selection into a frame, press Option+Cmd+G / Alt+Ctrl+G.
Auto layout: the smart tray¶
Draw a button by hand: a rectangle and a text on top. Now change the text from "OK" to "Confirm payment". The text sticks out of the rectangle, and you have to resize it yourself. Do that 200 times and you will see why Figma added auto layout in December 2019.
Auto layout arranges the layers inside a frame automatically, following a direction, a gap, padding and alignment.
Select the layers and press Shift+A. From then on, Figma does the spacing:
| Property | What it controls | In the button |
|---|---|---|
| Direction | Vertical, horizontal or grid | Icon and text side by side: horizontal |
| Gap | Space between the items | 8 px between the icon and the text |
| Padding | Space between the frame's edge and its contents | 12 px around the text |
| Alignment | Where the items sit inside the frame | Centred |
And each layer chooses how it is resized:
- Hug contents: the frame shrinks or grows to fit what is inside. A button that hugs its text is always the right width.
- Fill container: the layer stretches to take all the space its parent gives it. Useful for a full-width button.
- Fixed: the size never changes, whatever the content.
flowchart LR
T["<b>Text changes</b><br>'OK' → 'Confirm payment'"] --> H["<b>Hug contents</b><br>the button recalculates<br>its width"]
H --> P["<b>Padding + gap</b><br>stay exactly the same"]
P --> R["<b>Result</b><br>no manual resizing"]
Why should I care? Code works the same way
Auto layout is not a Figma invention. It copies how web pages are laid out in code: direction, gap, padding and alignment are the same ideas you will write in CSS in Unit 3. A design built with auto layout is much easier to turn into code.
Styles: one colour chart for everything¶
Your app's red appears on 300 layers. If each layer has the colour typed in by hand (#E10A1E), changing it means editing 300 layers. And you will miss some.
A style is a saved set of visual properties with a name, reused on many layers. Edit the style and every layer that uses it updates.
Figma has four kinds of style:
| Style | What it stores | Example |
|---|---|---|
| Colour (paint) | A fill or stroke: solid colour, gradient or image | Brand / Red |
| Text | Font family, size, line height, spacing | Heading / Large |
| Effect | Shadows and blurs | Shadow / Card |
| Layout guide | Rows, columns and grids | Grid / 12 columns |
This is the factory's colour chart: "Bright Red" is defined in one place, and every brick says "Bright Red" instead of mixing its own paint.
Variables: values that can change with the context¶
Figma presented variables at its Config conference in June 2023.
A variable stores one reusable value, such as a colour, a number, a piece of text or true/false, that you can apply to designs and change in one place.
The four types you will use most:
| Type | Stores | Example |
|---|---|---|
| Colour | A colour | background = white |
| Number | A number | spacing-m = 16 |
| String | Text | button-label = "Buy" |
| Boolean | True or false | show-icon = true |
Variables live in a collection: a set of related variables. The collection can have several modes. A mode is one column of values, with one value per variable. Light and dark mode are the classic example:
flowchart LR
V["<b>Variable</b><br>background"] --> L["<b>Light mode</b><br>white"]
V --> D["<b>Dark mode</b><br>almost black"]
L --> S1["Every screen<br>in light mode"]
D --> S2["The same screens<br>in dark mode"]
Switch a frame to the dark mode and every layer that uses the collection changes at once. Modes also work for languages (a String variable in English and in Spanish) and for device sizes.
Styles or variables?¶
They look similar, so here is the difference:
| Style | Variable | |
|---|---|---|
| Holds | A mix of values: a whole typography, a gradient, a shadow | One value |
| Several modes (light / dark) | No | Yes |
| Can point to another variable | No | Yes |
The two work together: a colour style can use a variable. In the factory, a style is a whole paint recipe. A variable is one entry in the colour chart that can have a day version and a night version.
Where does the name 'design token' come from?
Developers call these named values design tokens. A token is a name like color-background that designers and programmers share instead of passing raw values like #FFFFFF around. Figma's variables are its way of building design tokens inside the design file.
Components: the mould and its bricks¶
You have a good button now. You will need it on every screen. Copy and paste? Then you are back to editing 40 copies by hand.
A component is an element you can reuse across your designs. The original is the main component. Every copy is an instance linked to it.
Select the button and press Option+Cmd+K / Alt+Ctrl+K to create a component. Then drag instances from the Assets panel.
flowchart TB
M["<b>Main component</b><br>the mould: Button"]
M -->|"every change is sent to"| I1["<b>Instance</b><br>Home screen"]
M -->|"every change is sent to"| I2["<b>Instance</b><br>Login screen"]
M -->|"every change is sent to"| I3["<b>Instance</b><br>Settings screen"]
| Main component | Instance | |
|---|---|---|
| What it is | The original, the mould | A linked copy, a brick |
| Edit it and... | ...every instance updates | ...only that instance changes (an override) |
| Shortcut | Option+Cmd+K / Alt+Ctrl+K creates it | Ctrl+Option+Cmd+K / Shift+Alt+Ctrl+K jumps to its main component |
An instance can override some properties, for example its text or its colour, and still stay linked. You can always reset it to go back to the main component's values.
The detach trap
Right-click an instance and you will see Detach instance (Option+Cmd+B / Alt+Ctrl+B). It turns the instance into a normal frame, and the link is gone for good. The next time the main component changes, that copy stays behind. Detach only when you really want a one-off design.
Variants and component properties¶
A real button has several versions: primary and secondary, default and disabled, small and large. Making one component per version would give you a mess. Instead:
- Variants group all the versions of one component together, such as its different states, sizes or colours.
- Component properties are the controls an instance shows in the right panel, so you can change it without digging into its layers.
| Property | What it lets the instance do | Example |
|---|---|---|
| Variant | Choose one of the component's versions | State = Disabled |
| Boolean | Show or hide a layer | Show the icon: yes / no |
| Text | Change a piece of text | Label = "Buy now" |
| Instance swap | Swap a nested instance for another one | Swap the heart icon for a star |
In the factory: one mould with a few switches on the side. Flip a switch and you get the red version, the small version or the version without a hole.
For every shortcut on this page and many more, see the Figma shortcuts cheat sheet.
Key takeaways¶
- A frame is a container with its own size, style and constraints. Screens, cards and buttons are frames. A group just wraps its contents.
- Auto layout (Shift+A) arranges a frame's contents by direction, gap, padding and alignment. Hug contents makes a button fit its text.
- A style saves a named set of values (colour, text, effect, layout guide). Edit it once and every layer that uses it updates.
- A variable stores one value. Variables live in collections, and modes give each variable a different value per context, such as light and dark.
- A component is a reusable element. Changes to the main component reach every instance. Variants and component properties keep all its versions in one place.
- Detaching an instance breaks the link for good.
Quick check¶
1. You are designing a login screen for a phone. What should the screen be?
- A frame with a Phone preset
- A group of all the layers
- A component with no instances
- A layout guide style
Every screen starts as a frame (F). The right panel offers presets such as Phone, Tablet or Desktop, which give the frame the right size. A group has no size of its own: it just wraps its layers.
2. Why does a group not behave like a frame when you resize it?
- A group has no size of its own: it wraps its contents, and its layers cannot use constraints relative to it
- Groups are always locked and cannot be resized
- Groups can only contain text layers
- A group is just a frame with clip content turned off
A group's bounds adjust to fit the layers inside it. It has no fill, no clip content, no auto layout, and constraints always refer to the nearest parent frame, not to a group. That is why interface elements should be frames.
3. A button uses auto layout with Hug contents. You change its label from “OK” to “Confirm payment”. What happens?
- The button grows to fit the new text, and the padding stays the same
- The text sticks out of the button until you resize it
- The text gets smaller so it fits the old width
- The button keeps its width and the text is cut off
With Hug contents, the frame recalculates its size from what is inside it, keeping the same padding and gap. The text sticking out is what happens without auto layout, and that manual resizing is exactly what auto layout removes.
4. In auto layout, what is the difference between gap and padding?
- Gap is the space between the items; padding is the space between the frame's edge and its contents
- Gap is horizontal space; padding is vertical space
- Gap is only for text; padding is only for images
- They are two names for the same property
Gap separates the items from each other (the space between an icon and its text). Padding separates the contents from the frame's edge (the space around the text inside the button). Both work in any direction.
5. Your app needs a light theme and a dark theme. What is the best tool to switch every colour at once?
- Colour variables in a collection with a light mode and a dark mode
- One colour style per screen
- Detaching every instance and recolouring it
- Grouping all the dark layers together
Variables can have several modes: one value per variable in each mode. Switch a frame from the light mode to the dark mode and every layer that uses those variables changes at once. A style holds a single set of values and has no modes.
6. You change the corner radius of a main component. What happens to its instances?
- They all update, except any instance that was detached
- Nothing: each instance has to be edited one by one
- They are all deleted and must be placed again
- Only the instances on the current page update
An instance is a linked copy, so changes to the main component reach all of them. A detached instance is a normal frame now: the link is broken for good, and it keeps the old look.
7. Your button has a primary and a secondary version, each with an enabled and a disabled state. How do you keep them organised?
- One component with variants, for example Type = Primary/Secondary and State = Enabled/Disabled
- Four separate components with no link between them
- One group per version
- Detach an instance each time you need a different version
Variants group all the versions of one component together. Each instance then shows variant properties in the right panel, so switching from Primary to Secondary is one click instead of hunting for another component.
8. Your team changes the brand colour #E10A1E to a darker red. On which layers do you need to change the colour by hand?
- Only the layers with the colour typed in by hand; layers that use the colour style or variable update by themselves
- Every layer that is red, including those using the colour style
- None: Figma finds every red layer and changes it automatically
- Only the layers inside groups
A style or a variable is a single source of truth: edit it once and every layer that uses it updates. Layers with the raw value typed in have no link to anything, so you have to find and fix them one by one. That is the reason to use styles and variables from the very first screen.
You can now build screens from reusable pieces. Next, Design systems turns those pieces into the rules a whole product follows.