Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minimum line height to ensure text is not cut off

Tags:

css

fonts

Is there a standard for line height that ensures that a text is not cut off at the bottom or at the top irrespective of the setting (font family, font weight, font size, etc)?

A potentially reasonable value that one may think of may be 100%, or 1, but if I do line-height: 100%, or line-height: 1, the descend of letters like g, y are cut off at the bottom depending on the font. In my particular setting, line-height: 1.2 looks like the actual minimum.

Is there any (presumably relative) value for line-height that ensures that a part of a character is not cut off?

like image 953
sawa Avatar asked Aug 24 '14 08:08

sawa


People also ask

What is the best line height for readability?

Line height, or line spacing, is commonly measured as a percentage of font size. Conventional wisdom is that line spacing of 130%-150% is ideal for readability, but even up to 200% is acceptable. The perfect line height depends on the design and size of the font itself. There is no magic number that works for all text.

What is normal line height?

The default line-height is about 110% to 120% for the majority of the browsers. The line-height property sets the leading of lines of a text. If the line-height value is greater than the font-size value of an element, the difference will be the leading of text.

What is text line height?

Line height is the vertical distance between two lines of type, measured from the baseline of one line of type to the baseline of the next. Traditionally, in metal type, this was the combined measurement of the font size and the strips of lead that were inserted between each row (called “leading”) of type.

Can line height be less than font size?

If the value of the line-height property is smaller than the value of the font-size , text may overflow the element, and text on one line may overlap text on another line above or below it. It is often convenient to set the value of the line-height in the font shorthand property.


Video Answer


1 Answers

You can use line-height: normal which is the default:

normal

Tells user agents to set the used value to a "reasonable" value based on the font of the element. [...]

This leaves it up to the browser to determine the optimal line height based on factors such as font family, style and weight. See following example:

$(function() {
  $("p").each(function() {
    var h = $(this).height();
    $("<span style='background: #FC0;'></span>").text(" (" + h + "px)").appendTo(this);
  });
});
/* for Open Sans demo */
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap');

p {
  font-size: 16px;
  line-height: normal;
}
.font-1 p {
  font-family: sans-serif;
}
.font-2 p {
  font-family: monospace;
}
.font-3 p {
  font-family: "Open Sans";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<blockquote>
  All paragraphs have same font size. However, their &quot;normal&quot; line height vary depending on font face and other factors such as whether bold or italic text is present on the line box. Results vary across browsers as well.
</blockquote>
<div class="font-1">
  <p>Normal text</p>
  <p>Normal text and <strong>strong text</strong></p>
  <p>Normal text and <em>emphasized text</em></p>
</div>
<hr>
<div class="font-2">
  <p>Normal text</p>
  <p>Normal text and <strong>strong text</strong></p>
  <p>Normal text and <em>emphasized text</em></p>
</div>
<hr>
<div class="font-3">
  <p>Normal text</p>
  <p>Normal text and <strong>strong text</strong></p>
  <p>Normal text and <em>emphasized text</em></p>
</div>
like image 149
Salman A Avatar answered Oct 17 '22 22:10

Salman A