Spacing Text Without Extra Elements
Whitespace between characters and lines can come from markup or from CSS. Placing the break directly in HTML is one option:
<p>We go from one line...<br><br> down a couple more.</p>
Sizing and margins belong in CSS, though:
<p>We go from one line...<span>down a couple more.</span></p>
span {
display: block;
margin-block-start: 1.5rem;
}
line-height adds breathing room between lines, while letter-spacing, word-spacing and text-indent adjust text horizontally.
Creating Room Between Boxes
Two plain divs are block-level and already sit on separate lines. To separate them you can return to margin, use padding for the impression of space, or translate them in either direction:
<div>Twiddle Dee</div>
<div>Twiddle Dum</div>
div:nth-child(2) {
transform: translateY(100px);
}
Absolutely positioned elements accept physical offsets instead:
div {
position: absolute;
}
div:nth-child(1) {
inset: 0;
}
div:nth-child(2) {
inset-inline-start: 100px; /* or top: 100px; */
}
Layout-Dependent Spacing
Grid containers provide gap:
<section>
<div>Twiddle Dee</div>
<div>Twiddle Dum</div>
</section>
section {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 100px;
}
Flexible containers work the same way:
section {
display: flex;
gap: 100px;
}
Inside either container type, any alignment property can also be called on to generate space:
section {
display: flex;
align-items: space-between;
justify-content: space-between;
}
Tables offer their own spacing controls, and CSS can handle it too:
<table cellspacing="100">
<!-- etc. -->
<tbody>
<tr>
<td>Twiddle Dee</td>
<td>Twiddle Dum</td>
</tr>
</tbody>
</table>
/* We could use `display: table` if we're not working in a table element. */
table {
border-spacing: 100px;
}
Simulating Space
A linear gradient with a hard color stop can make a single element read as two. Adding a hard transparent color stop between the colors completes the illusion. The familiar transparent border trick falls into the same category.
For text wrapping around a floated element while keeping clearance from its edges, shape-margin applies. The spacer.gif era is another entry in the history.
div {
background-image:
linear-gradient(
to right,
rgb(255 105 0 / 1) 50%,
rgb(207 46 46 / 1) 50%,
rgb(207 46 46 / 1) 100%
);
}
<div>Twiddle Dee</div>
<img src="spacer.gif"> <!-- 🤢 -->
<div>Twiddle Dum</div>


