The CSS reference

"text-indent" - css property (v. css 1)

  • To specify the indentation of the first line in a text-block
  • The box is indented with respect to the left (or right, for right-to-left layout) edge of the line box.
  • Initial value: 0
  • The property is inherited
  • HTML usage: block-level elements, table cells and inline blocks
  • Browsers that support the text-indent - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible text-indent values:

value Comments CSS
length The indentation is a fixed length. With this you specify a positive(+) or negative(-) value followed with a unit identifier. 1
percentage The indentation is a percentage of the containing block width. 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 "text-indent" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <style type="text/css">
      div {border: blue 1px solid; color:blue;
           padding: 0.2em 0.2em 0.2em 0.4em; width: 400px;}
      div { text-indent: 3em }
    </style>
  </head>
  <body>
    text-indent with 3em<br>
    <div>To specify the indentation of the
      first line in a text-block.
      The box is indented with respect to the left (or right,
      for right-to-left layout) edge of the line box.
    </div>
   </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.textIndent="text-indent values"
// 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.textIndent;
/* 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.