日本語

How to Add Emphasis Marks (Bouten) Above Text with CSS

​​CSS​HTML,Japanese typesetting

To put an emphasis mark (bouten, also called kenten) above the characters you want to stress, use the CSS text-emphasis property. The browser draws the mark for each character, so you do not need to add any symbols to the HTML. For the "﹅" shape used for Japanese emphasis marks, write the shape as text-emphasis: sesame.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I installed Noto Sans CJK JP. I made only the emphasis marks red, took screenshots, and counted which red pixels were above or below which characters to check how the marks were placed. I did not test the display in Firefox or Safari. The browser versions listed for each browser are the values from the compatibility data (@mdn/browser-compat-data 8.1.8).

Applying text-emphasis to an em element

If you apply it to <em>, which carries emphasis meaning, the HTML stays as it is and the characters get emphasis marks.

html
<p>これは<em>大事</em>な話です。</p>
css
em {
  font-style: normal;
  text-emphasis: sesame;
}

In the Chromium test environment, the font-style of <em> was italic when nothing was specified. I also wrote font-style: normal so that the text would not be slanted.

Even when the marks appear on screen, the text string does not change. When I selected the paragraph in the HTML above and extracted the string (getSelection().toString()), it was the Japanese sentence meaning "This is an important point.", and it did not contain any emphasis mark symbols.

As stated on MDN's page for text-emphasis, text-emphasis is a shorthand that sets the shape (text-emphasis-style) and the color (text-emphasis-color), and it is inherited by child elements. In the test environment too, applying it to the parent paragraph also put marks on a <span> inside it, and writing text-emphasis: none on the <span> removed the marks there.

Without a shape, horizontal text gets small dots

The shape is chosen by combining a mark name with either filled (solid) or open (hollow). You can omit filled or open, and when omitted, it becomes filled.

A screen showing eight specified values stacked vertically. On the left are the specified values; on the right is a Japanese label meaning "add emphasis marks". filled sesame shows "﹅", open sesame shows a hollow sesame, filled dot shows a small black dot, filled circle shows a large black circle, open circle shows a white circle, filled double-circle shows a double circle, filled triangle shows a black triangle, and "✓" shows a check mark. One of each is placed above each character.
The values written in text-emphasis and how they appear in Chromium in the test environment. Character size is 34px

In the test environment, I measured the size of the marks on 32px characters, and the results were as follows.

Shape specified Mark Mark width
sesame ﹅ 10px
dot • 4px
circle ● 14px
double-circle ◉ 14px
triangle ▲ 14px
filled (shape omitted) • 4px

Be careful with the case where you write only filled and omit the shape. The CSS specification and MDN say that for horizontal text it becomes circle (●) and for vertical text it becomes sesame (﹅). In Chromium 153 in the test environment, for horizontal text the computed value was dot, and a small 4px-wide dot was drawn. For vertical text it was sesame. If you want the same shape in every browser, it is safer to write the shape name too.

You can also use any character as the mark. Write one character in quotation marks, such as text-emphasis: "✓". MDN's page for text-emphasis-style says not to write two or more characters. In the test environment, when I wrote "foo", the drawn mark was the same size as "f", and only "f" was placed.

For the color, either write it after the shape, as in text-emphasis: sesame #d85878;, or specify it with text-emphasis-color. If you do not write one, it is the same color as the text.

Punctuation, brackets, and spaces get no mark

Even if you wrap a part of a sentence together, punctuation and brackets do not get emphasis marks.

Two lines of text with pink emphasis marks. The first line is a Japanese sentence containing a comma, quoted "CSS", the particle "to", the digits 123, a full stop, an exclamation mark, and a question mark. The marks are on the kanji, the kana, C, S, S, the particle, 1, 2, and 3, but not on the punctuation or the space. The second line is "#%&@" followed by a long vowel mark, a katakana middle dot, and a wave dash. The marks are on #, %, &, @, and the long vowel mark, but not on the middle dot or the wave dash.
text-emphasis: filled sesame applied to the whole sentence. The pink marks are the emphasis marks

In the test environment, the results were divided as follows.

  • Characters that got a mark: kanji and kana, Latin letters, digits, the long vowel mark, and "#", "%", "&", "@"
  • Characters that did not get a mark: the Japanese comma, full stop, opening and closing corner brackets, exclamation mark, question mark, katakana middle dot, wave dash, and half-width spaces

The CSS specification says that separator characters such as spaces, and characters classified as punctuation in Unicode, are not given emphasis marks. "#", "%", "&", "@" and similar characters are classified as punctuation, but they are on the list of exceptions where marks are drawn. The results in the test environment matched this rule.

When line spacing is tight, only that line gets taller

As stated on MDN's page for text-emphasis-position, when there is not enough room, the line height increases, just as it does for ruby.

In the test environment, I put a mark on the third line of a paragraph of 16px characters that wraps to four lines. For each line-height, I compared the top position (from the top of the page) of the marked characters, with and without the marks.

line-height Without marks With marks Difference
1 52px 60px moves down 8px
1.5 72px 73px moves down 1px
1.8 84px 84px no change
2 92px 92px no change

With line-height: 1, only the line with marks had 8px of extra space above it compared with the previous line, and the line spacing became uneven. With a body line-height of around 1.8, the line positions did not change at this character size. When you apply marks where the line spacing is tight, such as in headings, it is a good idea to check the display.

Placing marks below, or on the left in vertical text

You change the position of the marks with text-emphasis-position. Because text-emphasis does not change it, you write it separately.

css
em {
  text-emphasis: sesame;
  text-emphasis-position: under;
}

In the test environment, when nothing was specified, the marks were above the characters in horizontal text, and with under, they were below the characters. In vertical text (writing-mode: vertical-rl), when nothing was specified, the marks were on the right of the characters, and with over left, they were on the left.

MDN's page says the initial value is auto, but the compatibility data shows that Chrome, Edge, and Safari do not support auto. In the Chromium test environment too, CSS.supports('text-emphasis-position', 'auto') returned false, and a declaration written with auto was ignored. The CSS Text Decoration Level 3 specification gives the initial value as over right (above in horizontal text, on the right in vertical text). MDN's page also says this position is preferred for Japanese. If you want to return a position that you changed elsewhere to this position, write over right instead of auto.

On the left is vertical text, a Japanese label meaning "emphasis mark on the right", with marks on the right of each character. On the right is horizontal text, a Japanese label meaning "add emphasis marks". Its first two characters have ruby readings "bou" and "ten", and the marks on those two characters are placed above the ruby. The marks on the characters without ruby are just above the characters.
Left: vertical writing. Right: marks applied to characters that also have ruby

When I applied marks to characters with ruby, the marks were placed above the ruby. As in the right side of the image above, the marks are at different heights for characters with ruby and characters without. The CSS specification also says that when the marks are on the same side as the ruby, they are placed outside the ruby. The specification also gives an example of how to remove marks from characters that overlap with ruby, using ruby { text-emphasis: none; } to remove the marks from ruby-annotated characters.

The ruby text itself (the reading "bou") did not get any marks. In the Chromium test environment, even when I wrote text-emphasis on the parent paragraph, the computed text-emphasis-style of <rt> stayed none.

Browser support

According to the compatibility data, the unprefixed text-emphasis is supported from Chrome 99, Edge 99, Firefox 46, and Safari 7 (iOS Safari 7 as well). Chrome 25 to 98 and Edge 79 to 98 support only -webkit-text-emphasis. In the Chromium 153 test environment, marks were drawn even when I wrote only -webkit-text-emphasis. If you also need to support older Chrome versions, write both, as in the MDN example.

css
em {
  font-style: normal;
  -webkit-text-emphasis: sesame;
  text-emphasis: sesame;
}

​Posted by 86