CSS guides

Keep an opaque fill available for outline lettering

·

An outline runs along the shape of each glyph. Set the stroke and fill independently, and check that the wording remains legible at the size you will use.

Text Stroke Generator

Compare filled and outline-only lettering

Select Reset example. Outline type uses a two-pixel stroke in #243B53 and a solid #B45309 fill. Select Outline only. A supporting browser keeps the outline and lets the preview background show through the glyph interior.

Switch the Preview background to Dark and compare how much of each letter remains readable. The preview background choice stays in the workspace.

Compare filled and outline-only lettering
ModeStroke widthFill in a supporting browser
Filled2 px#B45309
Outline only2 pxTransparent

WHATWG Compatibility Standard, text stroke properties

Check what happens outside the feature query

Download text-stroke.css and assign tm-stroke-text to the element. The base class declares the opaque fill color. The outline-only rule switches the fill to transparent only when the CSS stroke declaration is supported.

The forced-color rule restores the system text color to keep the phrase available without the decorative outline.

W3C CSS Conditional Rules Level 3, feature queriesW3C CSS Color Adjustment Level 1, forced colors

Check the shape of narrow letters

Replace the sample text with your final heading. Try increasing the stroke width from 2 to 4 pixels and review openings in letters such as e and a. Narrow interior details can get smaller as the stroke grows.

Use a smaller outline width or a wider-weight font when small openings become hard to see. In filled mode, a width of zero leaves the opaque fill.

WHATWG Compatibility Standard, text stroke properties

Common questions

Does the stroke property draw a border around the entire element?

It follows the painted glyphs. For a border around the element’s box, use the CSS border property.

How do I get an outline with a softer color?

Enter a stroke color with hex alpha. Keep some alpha and a positive width when using Outline only.

Sources

Put it into practice.

Related guides