CSS Reference

"line-height" - css property (v. css 1)

  • Sets the line height.
  • On a block-level, table-cell, table-caption or inline-block element whose content is composed of inline-level elements, this property specifies the minimal height of line boxes within the element.
  • Initial value: normal
  • The property is inherited
  • HTML usage: all elements
  • Browsers that support the line-height - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible line-height values:

value Comments CSS
normal Tells user agents to set the used value to a "reasonable" value based on the font of the element. 1
length The specified length is used in the calculation of the line box height. With this you specify a positive(+) (negative values are illegal) value followed with a unit identifier. 1
number The used value of the property is this number (negative values are illegal) multiplied by the element's font size . 1
percentage The computed value of the property is this percentage (negative values are illegal) multiplied by the element's computed font size. 1
inherit Will inherit the value from parent specification. This property value is new with CSS 2. 2

Possible unit identifier:

unit identifier Comments CSS
em The relative unit 'em' is relative to the font size of the element itself. 1
ex The relative unit 'ex' is relative to the font size of the element itself. 1
px Pixels, relative to the viewing device 1
in inches -> 1 inch is equal to 2.54 centimeters. 1
cm centimeters. 1
mm millimeters. 1
pt points -> the points used by CSS2 are equal to 1/72th of an inch. 1
pc picas -> 1 pica is equal to 12 points. 1

Property "line-height" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <style type="text/css">
      div {border: blue 1px solid; color:black;
           padding: .5em .5em .5em .5em; width: 400px;}
      .number { line-height: 2.2; }     /* number */
      .length { line-height: 10pt; }   /* length */
      .percentage { line-height: 160%; }    /* percentage */

    </style>
  </head>
  <body>
    <br>line-height: 2.2;  /* number */<br>
    <div class="number">The used value of the property
      is this number (negative values are illegal)
      multiplied by the element's font size.
    </div>
    <br>line-height: 10pt; /* length */ <br>
    <div class="length">The specified length is
      used in the calculation of the line box height.
      With this you specify a positive(+)
      (negative values are illegal) value
      followed with a unit identifier.
    </div>
    <br>line-height: 160%; /* percentage */ <br>
    <div class="percentage">The computed value of
      the property is this percentage
      (negative values are illegal)
      multiplied by the element's computed font size.
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.lineHeight="line-height value"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:
var value=cStyle.lineHeight;
/* The returned value is not cross-browser reliable. The value can vary in accuracy and notation, which depends on the browser, whether the value is preset or not and which option that was used to set the value.*/
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.