This topic has not yet been rated - Rate this topic

text-indent Attribute | textIndent Property

Gets or sets the indentation of the first line of text in the object.

Syntax

CSS { text-indent : sIndent }
Scripting [ sIndent = ] object.style.textIndent

Possible Values

sIndent String that specifies or receives one of the following values:
length
Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px). For more information about the supported length units, see CSS Length Units Reference.
percentage
Integer, followed by a percent sign (%). This value is a percentage of the width of the parent object.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of 0. The Cascading Style Sheets (CSS) attribute is inherited.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Remarks

The property can be negative. An indent is not inserted in the middle of an object that was broken by another object, such as br in HTML.

Examples

The following examples use the text-indent attribute and the textIndent property to indent the object's text.

This example uses calls to an embedded style sheet to change the indent on the text when an onclick event occurs. The text was originally indented 2 centimeters using div as a selector in the style sheet.


<STYLE>
    DIV { text-indent:2cm }
    .click1 { text-indent:50% }
    .click2 { text-indent: }
</STYLE>
</HEAD>
<BODY>
<DIV onclick="this.className='click1'"
    ondblclick="this.className='click2'">
. . . </DIV>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/text-indent.htm

This example uses inline scripting to indent the text within the div when an onmouseover event occurs.


<DIV onmouseover=this.style.textIndent="2cm"
:
</DIV>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/textIndent.htm

Standards Information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).

Applies To

BLOCKQUOTE, BODY, BUTTON, CENTER, CSSStyleDeclaration, currentStyle, DD, DFN, DIR, DIV, DL, DT, FIELDSET, FORM, hn, HR, ISINDEX, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, runtimeStyle, style, TABLE, TD, TH, TR, UL, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Proposal - text-padding

Suggestion: Have also, text-padding that applies to inner text (as inherited).

Reason: A container has inline text, objects, and, block elements, with different margin-padding requirements-- that should-not need negative-margins to fix the differences.... eg. container style=background-color should embrace all inline and block elements within, but presently block elements use negative-margins to thwart unwanted padding for text....

Note: text-padding flows around internal objects as well (currently padding does-not).

Note: text-indent (ie. first line) would add to text-padding.

Comment: not text-margin, because text-flow shouldn't be allowed to escape the container. (But then-again, it should cooperate with object margins within....)

Alternate: [text]-registration.

[tfl - 30 Sept 2008] You should probably make this suggestion over on Microsoft's connect site (http://connect.microsoft.com).