Yahoo Web Search

Search results

  1. Oct 3, 2020 · line-height can be set in px, em 's, every unit will fit. line-height works best and future proof if you use a factor/multiplier, meaning no unit, but only a number that is multiplying your font-size. .foo {. font-size: 1.3em; /* based that 1em == 10px */. line-height: 1.3; /* 16.9px line-height */.

    Code sample

    foo {
      font-size: 1.3em; /* based that 1em == 10px */
      line-height: 1.3; /* 16.9px line-height */
    }
    • Overview
    • Syntax
    • Accessibility concerns
    • Examples
    • Browser compatibility

    The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text. On block-level elements, it specifies the minimum height of line boxes within the element. On non-replaced inline elements, it specifies the height that is used to calculate line box height.

    Values

    normal\t Depends on the user agent. Desktop browsers (including Firefox) use a default value of roughly 1.2, depending on the element's font-family. (unitless)\t The used value is this unitless multiplied by the element's own font size. The computed value is the same as the specified . In most cases, this is the preferred way to set line-height and avoid unexpected results due to inheritance. \t The specified is used in the calculation of the line box height. Values given in em units may produce unexpected results (see example below). \t Relative to the font size of the element itself. The computed value is this multiplied by the element's computed font size. Percentage values may produce unexpected results (see the second example below).

    Use a minimum value of 1.5 for line-height for main paragraph content. This will help people experiencing low vision conditions, as well as people with cognitive concerns such as Dyslexia. If the page is zoomed to increase the text size, using a unitless value ensures that the line height will scale proportionately.

    W3C Understanding WCAG 2.1

    Basic example

    It is often more convenient to set line-height by using the font shorthand as shown above, but this requires the font-family property to be specified as well.

    Prefer unitless numbers for line-height values

    This example shows why it is better to use values instead of values. We will use two elements. The first, with the green border, uses a unitless line-height value. The second, with the red border, uses a line-height value defined in ems.

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

  2. Sep 5, 2011 · The line-height property defines the amount of space above and below inline elements. That is, elements that are set to display: inline or display: inline-block. This property is most often used to set the leading for lines of text. p { line-height: 1.35; }

  3. Set the line height for different <div> elements: div.a { line-height: normal; } div.b { line-height: 1.6; } div.c { line-height: 80%; } div.d { line-height: 200%; } Try it Yourself » More "Try it Yourself" examples below. Definition and Usage. The line-height property specifies the height of a line. Note: Negative values are not allowed.

  4. Apr 16, 2009 · Instead of “1.3em” – just “1.3”. There seems to be an issue, that when setting line-height: 1.3em cascades, it does so at a fixed pixel value relative to the current font-size. So, when using “1.3em” if a span or something increases that font-size, the line-height is not increased.

  5. length. Specifies the line height using a length value (for example 1.3em ). The specified length is used in the calculation of the line box height. Negative values are illegal. number. Specifies the line height using a number value (for example 1.3 ). The used value of the property is this number multiplied by the element's font size.