日本語

How to Draw Dotted and Wavy Underlines with CSS

​​CSS​HTML,Playwright

You can draw a dotted or wavy underline by writing underline together with a line style in text-decoration, such as text-decoration: underline dotted or text-decoration: underline wavy. You can choose from five line styles: dotted, dashed, wavy, double, and solid. You can also change the color, the thickness, and the gap between the line and the text with CSS. This article covers how to write those, how to fix a wavy line that breaks under English letters, and a way to write it that also works in Safari 26.1 and earlier.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I opened HTML and CSS pages with Playwright, recorded the values from getComputedStyle(), and took screenshots to record the pixel range where the line was drawn. The font size was 20px and the font was Noto Sans CJK JP. I did not test Firefox, Safari, or real smartphones.

Five Line Styles

Wrap the part you want to underline in a <span> or similar element, and give it a class.

html
<p>忙しいときは<span class="wavy">猫の手を借りる</span>のも一案です。</p>

In the CSS, write underline and a line style together in text-decoration.

css
/* Specify the underline style one at a time */
.dotted { text-decoration: underline dotted; }
.dashed { text-decoration: underline dashed; }
.wavy   { text-decoration: underline wavy; }
.double { text-decoration: underline double; }
.solid  { text-decoration: underline solid; }
Labels from top to bottom: dotted, dashed, wavy, double, and solid (default), with the Japanese text meaning "borrow a cat's paw". Each text has a pink underline. The dotted line is a row of fine dots, the dashed line is a row of short segments, the wavy line goes up and down, the double line is two parallel lines, and the solid line is one line. The labels are in Japanese.
Underlines drawn with the five text-decoration-style values. The line color is pink so they are easy to see

The line style is the value of the text-decoration-style property. When you write it inside the shorthand text-decoration, as in the CSS above, getComputedStyle() returned dotted or wavy for text-decoration-style.

I checked the line drawn under "borrow a cat's paw" (140px wide), and the results were as follows.

Value How it was drawn
dotted 35 dots, each 2px wide
dashed 14 segments, each 6px wide
wavy One connected line that moves up and down within a 7px vertical range
double Two lines, each 2px high, with a 1px gap between them
solid One line, 2px high

Line Color Can Be Set Separately from Text Color

If you do not specify a color, the line uses the same color as the text. (When I checked the <abbr> element described later, both the line color and the text color were rgb(31, 42, 48).) If you want to change only the line color and keep the text color, add a color at the end of the shorthand.

css
/* Draw a wavy line in a color different from the text */
.wavy-pink {
  text-decoration: underline wavy #d85878;
}

When I checked with getComputedStyle(), the line color (text-decoration-color) was rgb(216, 88, 120).

For Safari 26.1 and Earlier, Write Each Property Separately

According to the MDN compatibility data (@mdn/browser-compat-data 8.1.8), Safari added support for the shorthand text-decoration with a line style and color in version 26.2. Earlier versions of Safari only support the form with the -webkit- prefix. On the other hand, the form that writes text-decoration-line, text-decoration-style, and text-decoration-color separately has been supported in Safari since 12.1.

If you want dotted or wavy lines to appear even in older versions of Safari, write each property separately, as shown below.

css
/* Write each property separately so the line style and color work even in Safari 26.1 and earlier */
.wavy-longhand {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: #d85878;
}

In Chromium, writing the properties separately gave the same computed values as the shorthand, and the position and number of drawn pixels also matched.

Changing the Thickness Also Changes the Dot Size and Wave Height

You can change the line thickness with text-decoration-thickness.

css
/* Make dotted and wavy lines thicker */
.dotted-thick { text-decoration: underline dotted #d85878; text-decoration-thickness: 3px; }
.wavy-thick   { text-decoration: underline wavy #d85878;   text-decoration-thickness: 3px; }
Labels from top to bottom: dotted with no thickness set, dotted with text-decoration-thickness: 3px, wavy with no thickness set, and wavy with text-decoration-thickness: 3px, with the Japanese text meaning "borrow a cat's paw". The dotted line at 3px has larger dots and wider spacing. The wavy line at 3px is thicker and has a larger vertical range. The labels are in Japanese.
Dotted and wavy lines with no thickness set and with a thickness of 3px

When no thickness was set, the dotted line used dots 2px wide. At 3px, each dot became 3px square, and the number of dots in the same 140px width dropped from 35 to 24. The gap between dots also grew from about 2px to about 3px. The vertical range where the wavy line is drawn grew from 7px to 9px.

When no thickness is set, the value is auto, and the browser decides the thickness. With the 20px text used in this test, the height of a solid line was 2px.

If a Wavy Line Breaks Under English Letters, Lower It

When I drew a wavy line under English letters, it broke at letters like g and p that extend below the baseline. The wavy line under "Typography gjpq" (158px wide) was split into seven parts. According to the text-decoration-skip-ink documentation, with the default value auto, the browser may break the line so that it does not touch or come close to the letters. When I drew a dotted line under the same English text, the 158px width had 24 dots (with the 140px Japanese text, there were 35).

A wavy line is taller vertically, so the breaks are more noticeable. Lowering the line a little with text-underline-offset let it be drawn without breaks.

css
/* Move the wavy line a little away from the text */
.wavy-offset {
  text-decoration: underline wavy #d85878;
  text-underline-offset: 0.25em;
}
Two comparison images, one above the other. In the top image, "wavy, no position set," the wavy line under "Typography gjpq" breaks where it passes below the letters y, p, g, j, and q. In the bottom image, "wavy, text-underline-offset: 0.25em," the wavy line is drawn below the text and continues without a break from one end to the other.
Wavy line with no position set (top) and with a 0.25em offset (bottom)

With 20px text, 0.25em was 5px. With the offset, the wavy line moved from a range of 24 to 30px below the top edge of the <span> to a range of 28 to 34px, and it became one continuous line from end to end.

Also Usable for Other Decorations

Line styles can be used not only for underlines but also for strikethrough (line-through) and overline (overline). When I wrote text-decoration: line-through wavy #d85878, a wavy line was drawn around the middle of the text (12 to 17px below the top edge of the <span>, which was 29px tall).

Some browsers already draw dotted underlines in certain places. An <abbr> element with a title attribute had text-decoration-line set to underline and text-decoration-style set to dotted by default, without any CSS. The <abbr> documentation also says that some browsers draw a dotted underline under the content of this element, and that this style can be changed with text-decoration.

Browser Support

I checked the features used in this article with the MDN compatibility data (@mdn/browser-compat-data 8.1.8).

Feature Chrome Firefox Safari
text-decoration-style 57 36 12.1 (with -webkit- from 8)
text-decoration-line, text-decoration-color 57 36 12.1 (with -webkit- from 8)
Line style and color in the shorthand text-decoration 57 6 26.2 (with -webkit- from 8)
text-decoration-thickness 89 70 12.1
text-underline-offset 87 70 12.1

​Posted by 86