# Spacing: Build One Shared Scale So Related Things Group Together

> Learn how a small set of gap, padding, and margin values keeps screens ordered and shows which items belong together.

**In short:** Spacing is one shared scale of gap, padding and margin values built from a base unit, which keeps screens ordered and shows which items belong together.

From "Design systems", a free course by Venkat R. Murty: https://designervenkat.online/learn/design-systems/spacing

## What You Will Learn

Spacing is the set of empty areas that sit between screen parts and inside them. Those empty areas are gaps, padding, and margins. In a design system, teams do not pick these values by eye each time. They agree on a small set of values and reuse them on every screen. This lesson shows you how to build that set, how to use it to show which items belong together, and how to name each step so designers and builders pick the same values.

- **Spacing:** The empty room between and inside interface parts. A design system fixes which values of this room are allowed.
- **Gap:** The empty room between two items that sit side by side or one above the other.
- **Padding:** The empty room inside a box, between the box edge and the content in it.
- **Margin:** The empty room outside a box, between that box and the next thing.
- **Pixel (px):** One tiny dot on a screen. Most design tools measure gaps in pixels. The Units lesson covers other measures.
- **Base unit:** The smallest number that the rest of a spacing scale is built from, such as 8 pixels.
- **Scale:** A short, ordered list of allowed values, such as 8, 16, 24, and 32 pixels.
- **Proximity:** The idea that items placed close together look like one group, and items placed far apart look separate.
- **Gestalt:** A school of psychology that studies how people group what they see. Proximity is one of its rules.
- **Half-step:** A value between two main steps, such as 4 pixels, used for small fine tuning.

## Why Does Spacing Need a Scale?

Imagine two cards on one page. One card has 13 pixels of inner room. The other has 15. Each card looks fine alone. Side by side, the difference feels slightly wrong, even when the reader cannot say why. Small random values make a layout feel untidy. A scale stops this, because every gap comes from the same short list.

- **Hidden disorder:** Many near-identical numbers, such as 14, 17, and 15, make a page feel off even when each piece looks fine on its own.
- **Slow choices:** Without a list, each designer must decide every gap from nothing. Answers drift apart, and the team argues over tiny differences.
- **Easy reuse:** A short list means a builder can use the exact value the designer picked, so the two sides match without extra talk.

The fix is a rule, not a better eye. Teams call this kind of rule a scale. It says which values are allowed, and everyone works inside it.

### Why Do Random Numbers Look Wrong?

The layout feels subtly off, even when users cannot say why. The fix is to limit every spacing choice to values from one list, such as multiples of 8.

## How Do You Build the Scale From One Base Unit?

You do not need to invent a scale from scratch. You start with one base unit and build the steps from it. Here is the usual method.

1. **Pick one base unit:** Choose one number. Most teams choose 8 pixels. Teams with dense screens may choose 4 pixels. Pick one, and do not switch later.
2. **Multiply to make the main steps:** Multiply the base by 1, 2, 3, 4, and so on. With 8 pixels you get 8, 16, 24, 32, 40, 48, and 64.
3. **Add a half-step only where you need it:** Some small parts need less than 8 pixels. Add a 4-pixel half-step for those cases, and keep it rare.
4. **Write the full list:** Write the allowed values in one place. Give each one a name, such as small, medium, or large. The naming section below shows how.
5. **Write one use for each step:** Say where each step belongs. For example, the smallest step is for items that belong together, and the largest is for separate sections.
6. **Stop using off-list values:** If a value seems to be missing, first check the list. If the list really needs a new step, change it in one place for the whole team.

The formula below says the same thing as the steps. Each gap equals a step number times 8 pixels.

$$
\text{gap} = n \times 8\,\text{px}
$$

In words: take the step number, multiply it by 8, and you get the gap in pixels. So step 2 is 16 pixels, and step 4 is 32 pixels.

### Why Do Teams Often Pick 8?

The number 8 divides evenly by 2 and by 4, so you can still make halves and quarters when you need them.

### Add a 4px Half-Step for Fine Control

Use the 8-point steps between components and for component size. Material Design says iconography in toolbars aligns to a 4dp grid, and that all components align to an 8dp baseline grid. Keep the half-step for the small inner parts so the main rhythm stays clear.

## How Do Gaps Show What Belongs Together?

Spacing does more than make a screen tidy. It shows structure. Designers rely on proximity to show that items are related, without extra lines, boxes, or colors. Designary states the rule plainly: related objects get smaller spacing, and unrelated objects or separate sections get bigger spacing.

- **Tight: same item:** Use the smallest step for things that form one unit, such as a label and its field, or an icon and its text.
- **Medium: same section:** Use a middle step, such as 16 pixels, for items in one group. Fields in one address block fit here, and they still feel like parts of a whole.
- **Large: separate sections:** Use a big step, such as 32 pixels or more, between blocks that are unrelated.

### The Proximity Idea

Proximity comes from the Gestalt study of how people group what they see. Gapsy gives the same rule for interfaces: proximity says items are a group because they are close. When your gaps follow this rule, the reader sees the groups before reading a single word.

### Why Do Equal Gaps Hide Structure?

If every gap is the same size, the eye cannot tell which items form a group. Clear structure comes from contrast, meaning tight gaps inside groups and looser gaps between them.

> **Tip:** Cover the labels on a screen with your hand. If you can still see the groups from the gaps alone, your spacing is doing its job. If not, widen the gaps between groups or tighten the gaps inside them.

## Keep Inner and Outer Space Distinct

Padding and margin are easy to mix up. ConceptFusion draws the line clearly: padding is the space inside a component, and margin is the space outside it that separates it from others. A gap is the room between sibling items, such as two cards in a row. Keeping these three apart makes your spacing predictable.

- **Padding (inside):** Space between a box's edge and the content inside it. It stops text from touching the border of a card or button.
- **Margin (outside):** Space around a box that pushes it away from its neighbors. It keeps one component from crowding the next.
- **Gap (between siblings):** Space between items that sit in the same row or column, such as a list of cards or a set of form fields.

### Outside Space Should Be Larger

The most useful practical rule is that outside space should be larger than inside space. ConceptFusion says external spacing should be equal to or greater than internal spacing, otherwise the cards visually merge and their grouping becomes confusing. The same logic applies to headings: a heading should have less space below it than above it, so it stays with the text it introduces.

> **Tip:** Check your card in pairs. Measure the inside padding first, then the gap between two cards. If the gap is not larger, the cards will blur together on a busy screen.

## Why Name the Steps and Reuse Them?

A number like 16 is easy to forget and easy to mistype. A name like medium is easier to say in a review, and it tells the reader what the step is for. Name each step by its job, then use the same name in design files and in the product code the builders write. This keeps both sides using the same values.

- **Tight (4 px):** For items that are almost one unit, such as an icon and its label, or a label and its input.
- **Small (8 px):** For related items in one group, such as a short row of options or the parts of one small alert.
- **Medium (16 px):** For fields inside one section, and the usual padding inside a card or list item.
- **Large (24 to 32 px):** For separate groups on one page, such as Shipping and Payment blocks in a checkout.
- **Extra large (48 px or more):** For big gaps between major blocks, such as the space around a hero area or the edges of a page.

> **Tip:** Keep the list short. Naming conventions for these values are covered in the Defining Design Tokens lesson.

## Worked Example: A Checkout Screen

Here is a checkout screen of the kind found in many online shops. It has two sections, Shipping and Payment. Each section has a heading and a few labeled fields. The team wants the grouping to be clear without any divider lines. They use one scale with an 8-pixel base and a 4-pixel half-step.

1. **Set the label gap:** Each label sits 4 pixels above its input. The label belongs to its own field, so the tightest step is correct here. Users read the label and the field as one unit.
2. **Set the field gap:** The fields inside a section are 16 pixels apart. That is the medium step. The fields feel related, but each one still has room to be read and tapped.
3. **Set the section gap:** The Shipping section and the Payment section are 32 pixels apart. That is the large step. The bigger gap tells the eye that these are two separate blocks, so no divider line is needed.
4. **Check the contrast:** The label gap is smaller than the field gap, and the field gap is smaller than the section gap. Each step is bigger than the one before it, so the three levels of grouping are easy to read.
5. **Run the squint test:** Step back from the screen and look only at the shape of the spacing. If the two sections blur into one block, the section gap is too small. If a label seems closer to the field above than its own, the label gap is too large.

The result is a clean page with three clear levels of grouping and no lines at all. Every gap comes from the same short list, so a builder can copy the values exactly and the page keeps its rhythm.

## Common Mistakes to Avoid

- **Mixing arbitrary numbers:** Using 14 in one place and 17 in another breaks the rhythm. Pick every value from the scale, even when a near value looks fine.
- **Equal gaps everywhere:** Using one gap for every relationship hides the structure. Use tight gaps inside groups and larger gaps between them.
- **Outer space smaller than inner:** When the space between cards is smaller than the padding inside them, the cards merge. Keep outer space at least as large as inner space.
- **Labels floating in the middle:** A label placed halfway between two fields is equally close to both, so the user cannot tell which field it names. Keep each label closer to its own field.

## Check Your Understanding

Try these two short scenarios. Each one needs the ideas from this lesson to answer.

**Quick check:** Your app's card has 13 pixels of padding. Its title sits 22 pixels above the body text, and its button is 9 pixels below the text. A teammate's card uses 15, 20, and 10 pixels. Which approach should change, and what should replace the values so both cards match?

A. Keep your card and change the teammate's card to 13, 22, and 9 so the values match yours.
B. Change both cards to values from one shared scale, such as 16 pixels of padding, 8 pixels between title and text, and 16 pixels above the button.
C. Average the two sets, using 14, 21, and 9.5 pixels, so neither person has to change anything.
D. Keep both cards as they are, because a difference of 2 pixels is too small for anyone to notice.

**Answer:** B. Neither card uses a step from a shared list. The problem is the method of picking values by eye. Both cards should be rebuilt from one scale, with each gap given a job: padding inside the card, a tight gap for the related title and text, and a separate step above the button.

**Quick check:** A sign-up form has each label 16 pixels above its own field. The gap between one field and the next is also 16 pixels. Users keep typing their last name into the wrong box. What is the best fix?

A. Make every gap 24 pixels so the form feels evenly spaced.
B. Move each label up to 32 pixels above its field so it stands out more.
C. Add divider lines between the fields so each box looks clearly separate.
D. Tighten the label gap to 4 pixels and keep at least 16 pixels between fields, so each label sits closer to its own field.

**Answer:** D. The labels are as far from their own field as from the field above. A tight label gap and a clearly larger gap between fields makes the pairing obvious without lines. Equal spacing everywhere is the mistake that hides the structure.

## Key Takeaways

Spacing works best as a system. Pick one base unit, build a short scale of steps, and name each step by its job. Use tight gaps to join related items, and larger gaps to separate sections. Keep padding inside a box and margin outside it, and make the outside space larger than the inside. When every screen draws its gaps from the same list, the layout feels ordered, and the grouping works without extra lines.

## Sources

- [Material Design: Spacing methods](https://m2.material.io/design/layout/spacing-methods.html)
- [Material Design: Understanding layout](https://m2.material.io/design/layout/understanding-layout.html)
- [Material Design: Metrics and keylines](https://m1.material.io/layout/metrics-keylines.html)
- [Designary: Basics of spacing systems and scales in UI design](https://blog.designary.com/p/spacing-systems-and-scales-ui-design)
- [Gapsy: Proximity design principle guide](https://gapsystudio.com/blog/proximity-design-principle/)
- [ConceptFusion: Web design spacing and sizing best practices](https://www.conceptfusion.co.uk/post/web-design-spacing-and-sizing-best-practices)
- [Glow: Proximity principle of design guide](https://glow.team/blog/proximity-principle-design)
- [ScienceInsights: The principle of proximity](https://scienceinsights.org/what-is-the-principle-of-proximity-in-psychology/)
- [Breakdance: The 8-point grid system, a practical guide](https://breakdance.com/the-8-point-grid-system-a-practical-guide/)
- [Timgraf: Mastering the 8-point grid for spacing systems](https://timgraf.com/ui/mastering-the-8-point-grid-building-scalable-spacing-systems-for-modern-design-systems/)
- [Better Design: Spacing and layout principles](https://better-design.com/principles/ui/spacing)
- [MUI v4 documentation: Grid spacing](https://v4.mui.com/components/grid/)
- [Rejuvenate: The 8pt grid system for consistent UI spacing](https://www.rejuvenate.digital/news/designing-rhythm-power-8pt-grid-ui-design)
- [ioDroplet: Sizing, spacing and grids guide for UI/UX](https://iodroplet.com/an-ultimate-guide-on-sizing-spacing-grids-and-layout-in-web-and-ui-ux-design/)
