Sub topic 1
What white space is and why it matters
Prerequisites
This chapter assumes you know basic HTML structure (headings, paragraphs, lists, forms), basic CSS selectors and the box model, and how rem and em units work. You do not need to know anything about design theory.
What white space is
White space is the empty area on a page that holds no text, images or controls. It is also called negative space. It does not have to be white. A dark page with a dark background between elements has white space too.
White space appears at several scales:
- Between letters and words (letter and word spacing).
- Between lines of text (line height).
- Inside an element, between its content and its border (padding).
- Between elements (margin and gap).
- Around whole sections of the page.
In CSS you create white space with properties such as padding, margin, gap, line-height and letter-spacing. You never "draw" it. You leave room by adding distance.
Why it matters
White space does three jobs.
- It groups content. Items that sit close together look related. Items that sit far apart look separate. This is the main subject of this tutorial.
- It makes content easier to read. Text with enough room around it is easier to scan and follow.
- It sets priority. An element with a lot of space around it draws attention.
Most pages that feel cluttered do not have too much content. They have unclear groupings. When every gap is the same size, the reader cannot tell which items belong together, so every item competes for attention.
A before and after example
Consider a short product summary. In the first version, every element has the same margin.
<article class="product">
<h2>Trail Backpack</h2>
<p>Light, 30 litres, water resistant.</p>
<p class="price">$89</p>
<h2>City Backpack</h2>
<p>Slim, 20 litres, fits a laptop.</p>
<p class="price">$74</p>
</article>
<style>
.product > * {
margin: 0;
margin-bottom: 1rem;
}
</style>The gap between the heading and its description is 1rem. The gap between the price of one product and the heading of the next is also 1rem. The reader cannot tell where one product ends and the next begins.
Now group each product and use a small gap inside a group and a larger gap between groups.
<div class="products">
<article class="product">
<h2>Trail Backpack</h2>
<p>Light, 30 litres, water resistant.</p>
<p class="price">$89</p>
</article>
<article class="product">
<h2>City Backpack</h2>
<p>Slim, 20 litres, fits a laptop.</p>
<p class="price">$74</p>
</article>
</div>
<style>
.products {
display: grid;
gap: 2.5rem;
}
.product {
display: grid;
gap: 0.25rem;
}
.product h2,
.product p {
margin: 0;
}
</style>Nothing else changed: no borders, no background colours. The structure is visible because the space inside a product (0.25rem) is much smaller than the space between products (2.5rem).
Common mistakes
- Using one spacing value for everything. If the gap between a label and its input equals the gap between two sections, the page has no hierarchy.
- Treating white space as wasted room. Cutting spacing to fit more on screen usually makes the page harder to scan.
- Adding borders to fix grouping. Borders and boxes add visual noise. Try changing the distances first, and add a border only if spacing alone is not enough.
- Making gaps different by accident. Random values such as 13px, 17px and 22px look inconsistent. Later chapters show how to use a fixed spacing scale instead.
What comes next
The next chapter explains the proximity principle, the perceptual rule behind this behaviour. Later chapters give you CSS tools (a spacing scale, gap, and flow rules) to apply it consistently.
Exercise
A page has a heading, a paragraph and a button in one card, and then a second card below. Every element, including the two cards, has a 1rem gap between it and the next element. Describe one change that uses only spacing to make the two cards read as separate groups.
Show answer
Keep the small gap (for example 0.5rem to 1rem) between the heading, paragraph and button inside each card, and increase the gap between the two cards to something clearly larger, such as 2.5rem. The larger outer distance shows that the cards are separate groups without adding borders.