Layered Text Headers
Layered Text Headers ź“ė Ø
There is a way to apply a stroke to web text across all browsers:
.stroke-text {
-webkit-text-stroke: 5px red;
}
Despite the vendor prefix there, it works across all browsers.
But Iāve never liked it⦠until recently.
Iām not sure if Iāve ever spelled out exactly why, so first let me do that. Hereās a nice R from Roslindale.

Which is made up of vector points like all fonts:

In an application like Adobe Illustrator which gives me control over how a vector shape applies a stroke, if I stroke the outside it ends up looking OK as the integrity of the letterform is preserved.

Itās a bit harder to do with Roslindale āRā with the narrow passages at the top and middle of the letterform here, but we can apply stroke to the inside as well and the overall shape of the letter stays the same.

But if we apply a stroke to the āmiddleā, that is, straddled across the edge of the shape such that the stroke is equal on both sides, now weāve ruined the shape of the letter and it looks like š©.

This is even more pronounced as we deal with more text.

Middle: Inside stroke
Bottom: Center stroke š©
Point is: center aligned stroke sucks. And guess what the only option is for -webkit-text-stroke
? Center-aligned. And, equally sadly, all strokes in SVG, a bonkers omission for a vector painting specific language.
Alas there is a half decent and kinda fun workaround. The trick is essentially using paint-order
(which works in CSS and SVG) to make sure that the āfillā of the element is drawn on top of the āstrokeā, which effectively makes the stroke appear as if itās outside-aligned even if itās not actually doing that.
.stroke-text {
paint-order: stroke fill; /* fill is on top */
-webkit-text-stroke: 5px red;
}
With this combo we can make stroked text tolerable:
Just putting that fill on top can fix some different awkward situations. Hereās Adam Argyle showing how a text-shadow
can really interfere, and then fixing it by forcing that fill layer back on top again.
Wes Bos showed this off, layering on some text-shadow
stuff as well, which resulted in a great look:
I had a play as well, and I really like the combination of being able to use a text stroke safely and being able to use a text shadow for an additional effect. Here the shadow comes up on top of the text giving it an actual embossed look:
You could have a play with this one, adding more text shadows or adjusting colors or whatever to get a nice look.
Perhaps goes without saying but Iāll say it anyway: thicker typefaces are going to generally work better with this.