Like the graphic design of a physical poster, sometimes we need some eye-catching text on the web too. Picking the right font is just the beginning. Text weight, style, spacing, and decoration can go a long way, but sometimes we need more to make the text stand out.
Here are five properties that can help make words look better, or at least more interesting, on the web. They are all fairly simple implementations you can layer into other ideas.
1. background-clip
The fill of the letterforms is usually a solid color in typography (with some wild exceptions). But it’s rather easy to use an image to fill that space instead. All we’ve got to do is pick a fancy background and snip it to the shape of our text. The result is a set of striking knockouts that can be read.
In the late 2000s, the text value was introduced for the background-clip property, making it possible to mask background images (or gradients) inside live text. Since then, it has remained one of the most sought-after rules for really cool typography visuals.
<p>Belize Reef</p>Code language: HTML, XML (xml)
p {
/* `background-clip: text` included in the shorthand */
background: text url("image.jpg") center/auto 1lh;
/* transparent text so that the clipped background is visible underneath */
color: transparent;
}Code language: CSS (css)
2. vertical-align / align-content
On occasion, the basics build the brilliance.
We all could align text horizontally since we could write CSS (text-align: center;). But when it comes to the vertical axis, the text alignment doesn’t always go smoothly. However, understanding these two properties should resolve most of that.
The vertical-align property hails from the era of the Early Web, when HTML tables ruled the layout landscape. It was widely used to align content inside a table cell. However, outside of a table cell, it’s not really about aligning text vertically; rather, it’s about aligning inline elements to the text.
If something goes into a line of text, like span, img, or input, and has to line up relative to the text, vertical-align is how it’s done.
31 B<span class="emoji">💺</span>Code language: HTML, XML (xml)
.emoji {
vertical-align: top;
}Code language: CSS (css)
What we all might have initially thought vertical-align did — aligning text vertically in a box — is actually done by the relatively newer property, align-content.
Evolved in the Modern Layout era, other than flex box and grid, align-content also affects the block box and arranges the box’s content vertically.
<p>Bonjour</p>Code language: HTML, XML (xml)
p {
width: 360px;
aspect-ratio: 1;
text-align: center;
/* No grid or flexbox needed anymore */
align-content: center;
}Code language: CSS (css)
3. box-decoration-mode
We don’t usually think line by line for typography design. However, if we ever do go line by line, this property is all we need, and frankly, it’s all we have.
There’s a CSS standard module to handle when content breaks along a flow, column, or page, termed fragmentation. But that was all only about deciding on the spacing, wrapping, and location of the break until box-decoration-mode came along to tackle the styling.
When a text’s line box breaks, the broken edge is typically unstyled, causing an awry appearance at the edges of the fragments. But with box-decoration-mode we can ensure all the fragments’ edges are uniformly styled. Which means they all get the borders, shadows, etc. that were applied to the element at the edges.
<span>
water cooler chat <br>
everyone agrees <br>
it is hot
</span>Code language: HTML, XML (xml)
span {
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
/* the edge styles */
border: solid blue;
border-width: 0 1px 1px 0;
box-shadow: 2px 2px 3px rgb(171, 171, 245);
padding-inline: 6px;
border-radius: 3px;
}Code language: CSS (css)
4. letter-spacing
The letter-spacing property is underappreciated not only for the typographical aesthetic, but also for animation.
There is no way in CSS to target the individual glyphs in a text (except the first one). But letter-spacing somewhat does that, since it determines the trailing space of all the glyphs in a text. The spacing accepts both positive (putting distance) and negative (shrinking gap) values.
An animation of the same yields a text reveal effect.
<section id="text">
<span>Ingvar</span>
<span>Kamprad</span>
<span>Elmtaryd</span>
<span>Agunnaryd</span>
</section>Code language: HTML, XML (xml)
span {
/* Shrink and hide the letters */
letter-spacing: -1ch;
color: transparent;
/* Keep the first one visible */
&::first-letter {
color: #FBDA0C; /* yellow */
}
/* On expansion */
body:has(:checked) & {
/* Expand and show the letters */
letter-spacing: 0ch;
color: #0057AD; /* blue */
transition: letter-spacing 0.4s cubic-bezier(.8, -.5, .2, 1.4), color 0.8s linear;
}
}Code language: CSS (css)
5. text-combine-upright
text-combine-upright is made for East Asian typography, where short texts are sometimes written in small size as a vertical sentence.
This means this works only when the writing mode is set to vertical.
In LTR (left-to-right) languages, like English, occasionally we opt for vertical writing either to save space or for its appearance. It’d be great if we could still include some horizontal text.
<p>2 Kilo <span>4 lb</span>Sugar</p>
<p><span>🏂</span><span>Feb</span>02/26</p>Code language: HTML, XML (xml)
p {
writing-mode: vertical-lr;
span {
text-combine-upright: all;
}
}Code language: CSS (css)
There are plenty of properties that can be useful for typography design, but these five should give you a head start and an understanding of how typography is approached with CSS and what aspects of typography we can work with for some good detailing.
