CSS guides

Place an underline around letters with descenders

·

A descender such as the tail of a g can meet a decorative line. Adjust its position and whether the browser skips the ink before reusing the style.

Text Decoration Generator

Start with the wavy three-pixel underline

Select Reset example. Rising type uses a wavy underline, three pixels of thickness and six pixels of underline offset. Change the sample to early glyphs to add several descenders.

Switch Skip ink to Draw through glyph ink and compare the line with the automatic setting. The automatic behavior depends on where your browser paints the line around the glyphs.

Start with the wavy three-pixel underline
SettingExample valueCSS property
Line stylewavytext-decoration-style
Line thickness3 pxtext-decoration-thickness
Underline offset6 pxtext-underline-offset
Draw through glyph inknonetext-decoration-skip-ink

W3C CSS Text Decoration Level 4, line decorationsW3C CSS Text Decoration Level 4, underline offset and ink skipping

Compare two decoration lines on the same text

Select Strike-through as well as Underline. The output contains underline line-through in one text-decoration-line declaration. The style, color and thickness apply to both lines.

Change Underline offset to 10 pixels and compare before and after. The underline moves relative to its default position. The strike-through stays governed by the browser’s line placement.

W3C CSS Text Decoration Level 4, line decorationsW3C CSS Text Decoration Level 4, underline offset and ink skipping

Apply the exported class to the target element

Download text-decoration.css and include it in your project. Apply tm-decorated-text to the element you want to decorate. The preview phrase is working text, so use your own content.

If a different font changes how the decoration sits on the letters, try From font in Thickness source to use the font’s available metrics. Recheck both wrapped and single-line text.

Example of choosing where the underline sits
text-decoration-line: underline line-through;
text-decoration-thickness: 3px;
text-underline-offset: 10px;

W3C CSS Text Decoration Level 4, underline offset and ink skipping

Common questions

Can I set separate colors for the underline and strike-through?

One generated rule shares its decoration color. Separate elements or additional CSS rules can originate separate decorations.

What happens if the font has no decoration thickness metrics?

For from-font, the browser falls back to its automatic thickness choice.

Sources

Put it into practice.

Related guides