Remove space below the text baseline with CSS

Rose Kunkel picture Rose Kunkel · Aug 10, 2016 · Viewed 12.3k times · Source

Lately I've been working with Japanese text, and I've found a rather annoying property. In Japanese, unlike English, glyphs do not extend below the text baseline. This example should show what I mean:

Notice how the "g" in "English" extends below the underline, but none of the characters in 日本語 do. This is typical of Japanese text. Despite this, space is still reserved below the underline, and in fact on my screen the Japanese text reserves more space than the English text does. My question is this:

Is there a way to remove this space with CSS which is reliable across changing fonts and font sizes? I can see at least two possible approaches:

  • Remove the space below the baseline directly.
  • Move the baseline to be at the bottom of the containing box.

Answer

Juan Ferreras picture Juan Ferreras · Aug 10, 2016

You need to reset the line-height so it's not bigger than 1. The initial value is normal which depends on the User Agent of the browser, on the font-family and on the font-size, but it's some number between 1 and 1.2 in general. Here's more information if you're interested.

div {
  font-size: 72pt;
  display: inline-block;
  text-decoration: underline;
  border: 1px solid red;
  margin: 10px;
  text-align: center;
  line-height: 1;
}
<div lang="ja">日本語</div>
<div lang="en">English</div>