# Spaces: Building a Consistent Rhythm of Gaps, Padding, and Margins

> Learn how a small set of agreed spacing values, built on one base unit, keeps layouts tidy and easy to hand off.

**In short:** Spaces are a small set of agreed spacing values built on one base unit, which keep gaps, padding and margins consistent and layouts easy to hand off.

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

## What you will learn

In design systems, Spaces means the agreed set of spacing values. These values set the gaps, padding, and margins between and inside elements. A spacing value is just an amount of room, such as 16 pixels. Spaces is the rulebook for how much room things get. It is not the things themselves. By the end of this lesson you will be able to pick a base unit, build a short scale, decide which kind of space to use, name each step, and check a layout against the scale.

- **Base unit:** The smallest step in your spacing system. Every other space value is a multiple of it.
- **Spacing scale:** A short, fixed list of allowed space values, such as 4, 8, 16, and 24 pixels. Designers use only these values.
- **Pixel (px):** A tiny dot on a screen. Spacing values are often written in pixels. Material Design uses a similar unit called the dp, which is a density-independent pixel.
- **Padding:** The space inside an element, between its edge and its content.
- **Margin:** The space outside an element, between it and its neighbors.
- **Gap:** The space between items that sit side by side or stacked inside one container.
- **Gutter:** The space between columns in a page grid.
- **Proximity:** The idea that things placed close together look related, and things placed far apart look separate.

## Why does a spacing scale exist?

Imagine five designers each choose their own gaps. One uses 13 pixels, another 15, another 14. Each choice looks fine alone. Together the product feels slightly off, and nobody can say why. A spacing scale fixes this. It gives the whole team a short list of allowed values. Without it, each component invents its own padding and the layout slowly drifts apart. With it, designers can ask a simple question in review: is this 12 or 14? The scale answers it.

> **Tip:** A scale does not make a design pretty by itself. It removes guesswork, so the team spends its energy on layout and content instead of tiny numbers.

## Step one: pick a base unit

The base unit is the starting point for the whole system. Every space value is built from it. In many digital products the base unit is 4 pixels or 8 pixels. Some teams choose 10, but 4 and 8 are the most common because they divide evenly and make the math easy. Once you choose, every margin, padding, and gap should come from that number or a multiple of it.

The base unit sets how precise your layouts can be. A smaller base gives more choices. A larger base gives fewer, bolder choices.

Choosing the base is a team decision. Write it down, then test it on real components before you commit.

- **Choose 8px for most products:** An 8-pixel base is simple and bold. Many guides call it the safest default for websites, apps, and dashboards that run on several screen types.
- **Choose 4px for dense products:** A 4-pixel base gives finer control. It suits tools with many small controls, such as data tables or compact forms.
- **Use both when needed:** Many teams use 8 as the main rhythm and allow 4 as a half step inside small parts, like an icon and its label.

> **Tip:** If you are unsure, start with 8. Add a 4-pixel half step only when a small component really needs it.

## Step two: build a limited scale

After the base unit, list the multiples you will allow. This list is the scale. Keep it short. Too few values limits designers. Too many values make every choice hard. A simple 8-pixel scale might be 4, 8, 16, 24, 32, and 48. Each value has a clear job, so designers and developers use the same words for the same space.

- **4 px:** Tight spaces inside small parts, such as an icon beside its label.
- **8 px:** Related items close together, such as a title and the line beneath it.
- **16 px:** Standard padding inside a card, or space between separate pieces of content.
- **24 px:** Space between cards or between groups of content.
- **32 px and 48 px:** Large breaks, such as between sections of a page.

Material Design takes a similar route. Its spacing system is measured on an 8dp scale. Teams can add more values later if they need them.

## What are the three kinds of space?

Not every gap plays the same role. A good spaces system names the job each value does. Spacing can be sorted into padding, margin, and gap. A fourth group, layout spacing, covers the space around whole pages.

- **Padding (inside):** Space between an element's edge and what sits inside it. A button's label needs padding so it does not touch the button's border. Padding only really shows when the element has a background or a border.
- **Margin (outside):** Space outside an element that pushes its neighbors away. Margins are useful, but many systems use them rarely because they are harder to control when parts are reused.
- **Gap (between):** Space between items inside one container, such as the stack of items in a list or the row of tags in a filter bar. The gap belongs to the container, not to each item, so it stays consistent when items change.
- **Layout spacing (page level):** Space that frames whole screens. This includes page margins at the edges, gutters between columns, and space between sections of a page.

Each kind answers a different question. Padding asks how far content sits from its own edge. Gap asks how far items sit from each other. Layout spacing asks how far the whole screen breathes.

> **Tip:** Before you pick a value, ask which of the three kinds it is. Padding, margin, gap, and layout spacing each have their own place on the scale, and naming the kind first stops you from mixing them up.

### Rules for padding, margin, and gap

Design systems usually follow a few simple rules to avoid tangles. The first rule is to prefer gaps and padding over margins inside components.

If a card's inner padding is bigger than the space between two cards, the cards will look like they belong together. Set the outer space larger so each card reads as its own unit.

- **Use padding with a background:** Add padding inside an element only when it has a visible background or border. Otherwise the padding is invisible and confuses people reading the file.
- **Let the parent control gaps:** If a card has its own built-in outer margin, the page that holds several cards cannot control the spacing between them. Leave the outside space to the layout.
- **Keep tap areas separate from visual gaps:** The space you see is not always the area a person can tap. Make sure clickable areas stay large enough, even when the visible gap is small.

> **Tip:** Before you add a margin, ask whether a gap in the parent container would do the same job. Most of the time it will, and the result is easier to change later.

### Layout spacing: margins, gutters, and sections

Layout spacing is the largest group. It shapes how a screen breathes. Page margins are the empty edges on the left and right of a screen. Gutters are the gaps between columns. Section spacing separates one part of a page from the next.

Page margins usually grow as screens grow. Material Design's older guidance lists gutters of 16 and 24.

> **Tip:** Keep layout spacing on the same scale as component spacing. Your page margin, card gap, and section gap should all be values from the same list.

## How does proximity group related items?

Spacing does more than fill room. It tells people what belongs together. This idea is called proximity. Items that are close look related. Items that are far apart look separate. Designers can use proximity on purpose, so people understand a screen without reading every word.

The 4-pixel gap made an icon look attached to its label, while the 8-pixel gap kept separate components apart.

- **Tight means related:** Use the smallest value on the scale for things that must be read together, such as a label and its input.
- **Medium means same group:** Use a middle value for items in one group, such as several fields in one form section.
- **Large means new topic:** Use a bigger value to show a change of subject, such as the start of a new section.

**Quick check:** In a sign-up form, each label sits just above its input. The next field starts a new topic called Billing. Using a scale of 4, 8, 16, and 24 pixels, which spacing best shows this structure?

A. 24 px between each label and its input, and 8 px before the Billing heading
B. 8 px between each label and its input, and 24 px before the Billing heading
C. 16 px between every item so the form looks even and consistent
D. 4 px before the Billing heading so the form stays as compact as possible

**Answer:** B. Proximity works best when related items sit close. The label and input stay tight at 8 px, and the bigger 24 px gap signals a new topic. Equal spacing everywhere would hide the grouping.

## How do you name the spaces?

Numbers alone are easy to mistype and hard to discuss. Names solve this. Teams give each scale value a short name, such as small, medium, or large. Then designers and developers can say space-md instead of 16 pixels. The name stays the same even if the number changes later.

1. **Write down the scale:** List every allowed value in pixels, such as 4, 8, 16, 24, 32, and 48. Do not add values during a project without a team decision.
2. **Give each value a short size name:** Use a simple pattern such as xs, sm, md, lg, xl, and 2xl for small to large. For this scale, 4 becomes space-xs, 8 becomes space-sm, 16 becomes space-md, 24 becomes space-lg, 32 becomes space-xl, and 48 becomes space-2xl.
3. **Name by job when it helps:** Some teams add a name that describes the use, such as card-padding or section-gap. Keep these names neutral so they still work across platforms, because a pixel value on a phone may not match one on a desktop.
4. **Document the purpose:** Next to each name, write one line that says where it is used. This helps new designers pick the right value without guessing.
5. **Check the names in real screens:** Build one screen with the names, then look for any space that is still off the scale. Fix it or add a documented exception.

> **Tip:** Keep names short and stable. A name like space-md should mean the same thing on every screen, even after the team changes its numbers.

## How do you use the scale across screens?

A good scale works for every component and every screen. Use the same values for the same jobs. A button, a card, and a form should all draw their padding and gaps from the same list. When the scale is shared, a new screen can be built faster, and it will look like the rest of the product.

Some dense interfaces need a tighter look. Do not scatter one-off smaller numbers across the screens. Instead, document a compact version of the scale and use it on purpose.

- **Reuse, do not reinvent:** Before you add a new value, check whether an existing name already fits.
- **Keep the same names across screens:** A card on the home page and a card in search should use the same padding name.
- **Record exceptions:** If a special case needs a different value, write it down and explain why.

Screens also change size. A layout that fits a laptop may need smaller margins on a phone. Many teams keep the same names but set different values for each screen size. Design tools can help here, because they let you define values for desktop, tablet, and mobile separately.

> **Tip:** When you start a new screen, list its spaces by job first, then pick the matching names. Doing it in this order keeps the screen on the scale from the start, instead of fixing stray numbers later.

### Responsive adjustments

Responsive design means a layout adapts to the screen it is shown on. Spacing should adapt too, but within the rules. Keep the names the same and change only the values. For example, page margin might be space-md on a phone and space-xl on a desktop. The job stays the same, so the system stays readable.

> **Tip:** Change the value, not the name. If a designer must invent a new name for each screen size, the scale is not doing its job.

## Worked example: a listing card

This example uses a made-up listing card in the style of a travel booking site. It is not Airbnb's real design. It shows how a messy layout becomes a clean one on an 8-pixel scale. The card has a photo, a title, a price, and a short line of detail. Several cards sit in a row.

In the messy version, the gaps are 13 pixels between the photo and title, 17 pixels between the title and price, and 22 pixels between cards. Padding inside the card is set by eye. None of these numbers appear on the scale, so the team cannot tell which values are intentional.

1. **Find the off-scale values:** List every number in the file. The values 13, 17, and 22 are not multiples of 4 or 8, so they do not belong to the scale.
2. **Choose the scale:** Use an 8-pixel base with the values 4, 8, 16, 24, 32, and 48. Write these down so the team can see them.
3. **Set the padding inside the card:** Give the card 16 pixels of padding on every side. This is a standard space for content inside a bordered box, and the card has a background, so padding shows.
4. **Set the space between title and price:** Use 8 pixels. The title and price are closely related, so the small gap groups them together.
5. **Set the space between cards:** Use 24 pixels. Each card is its own unit, so the gap between cards must be larger than the gap inside a card.
6. **Move the photo gap to the scale:** Change the 13-pixel gap between photo and title to 16 pixels, which is the nearest scale value that keeps the card's rhythm. Change the 17-pixel gap to 16 as well, so the card uses fewer values.
7. **Name and hand off:** Call the card padding space-md, the title-to-price gap space-sm, and the card-to-card gap space-lg. A developer reading the file now sees the same words the designer used.

> **Tip:** After the rebuild, compare the two versions side by side. The clean version usually reads faster because the groups are clear and the spacing repeats across cards.

## Common mistakes to avoid

- **Adding values as you go:** A new value for every small problem makes the scale useless. Check the list first.
- **Using margins everywhere:** Margins are harder to control in reused parts. Prefer gaps and padding.
- **Making inner space bigger than outer space:** Items inside a card should not look farther apart than the cards themselves.
- **Ignoring the screen size:** A margin that looks right on a laptop can crowd a phone. Test each screen size.

## Check your understanding

A teammate sets a button's padding to 10 pixels and the card next to it to 15 pixels, because it looked right. The team uses a 4-pixel scale. Read the question and pick the best answer.

**Quick check:** Using a 4-pixel spacing scale, what should you change, and why does it help the team?

A. Keep both values, because a designer's eye is the best judge of spacing
B. Set the button to 8 or 12 pixels and the card to 16 pixels, then use the scale names, so everyone shares one vocabulary
C. Set both to 12 pixels so the two values match each other, because matching numbers are always better
D. Set the card to 14 pixels so it sits between 10 and 15, which keeps the layout smooth

**Answer:** B. Ten and 15 are not multiples of 4. Eight, 12, and 16 are. Using scale values gives the team a shared vocabulary, fewer decisions to make, and an easy way to check spacing in review.

Spaces is a rule for room, not for the things that fill it. When you choose a value, ask what job it does, pick the matching name from the scale, and check the result against the screen.

## Summary

- **Pick a base unit:** Choose 4 or 8 pixels, and build every space from it.
- **Build a short scale:** Keep a small, shared list of multiples, such as 4, 8, 16, 24, 32, and 48.
- **Sort spaces by job:** Use padding inside, margin or gap between, and layout spacing for the page.
- **Name and reuse:** Give each value a name such as space-md, and use it the same way on every screen.

## Sources

- [Material Design 3: Spacing](https://m3.material.io/styles/spacing)
- [Material Design (2014 docs): Spacing methods](https://m2.material.io/design/layout/spacing-methods.html)
- [Material Design: Responsive UI, margins and gutters](https://m1.material.io/layout/responsive-ui.html)
- [Honcho: Spacing scale in a design system](https://honcho.agency/design-systems/glossary/spacing-scale)
- [Breakdance: The 8-Point Grid System, A Practical Guide](https://breakdance.com/the-8-point-grid-system-a-practical-guide/)
- [Irfan Rafeek: Spacing components in design systems](https://www.irfanrafeek.com/post/spacing-components-in-design-systems)
- [Design Systems Collective: Design system best practices, Variables](https://www.designsystemscollective.com/design-system-best-practices-variables-d8e4c351a430?gi=bbbb1d14bf60)
- [Marvel: A harmonious spacing system for faster design-dev handoff](https://marvelapp.com/blog/harmonious-spacing-system-faster-design-dev-handoff/)
- [Cieden: Spacing recommendations for desktop and mobile designs](https://cieden.com/book/sub-atomic/spacing/spacing-for-desktop-and-mobile-designs)
- [Design Overflow: Spacing Calculator](https://www.designoverflow.co/tools/spacing-calculator)
- [Basic Free Tools: Spacing System Calculator](https://basicfreetools.com/spacing-system-calculator/)
- [UX Planet: Principles of Spacing in UI Design, the 4-Point Spacing System](https://uxplanet.org/principles-of-spacing-in-ui-design-a-beginners-guide-to-the-4-point-spacing-system-6e88233b527a?gi=f73fc558f460)
- [ConceptFusion: Web Design Spacing and Sizing Best Practices](https://www.conceptfusion.co.uk/post/web-design-spacing-and-sizing-best-practices)
- [Design Project: UI spacing system, tokens and CSS examples](https://designproject.io/resources/guides/create-spacing-system/)
- [Thridy: The 8-Point Grid System, A Guide to Consistent Spacing](https://thridy.com/blog/the-8-point-grid-system-how-spacing-in-eights-makes-ui-feel-consistent)
