textIndent Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:textIndent

Description

The textIndent property sets or gets the indentation of the first line of text.

Negative values are allowed, which makes the first line indent to the left.

Property Values

Value Description
length Defines the indentation in length units. Default value is 0
% Defines the indentation in percentage of the width of the parent element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: 0
Return Value: A String, representing the indentation of the first line of text in the element
CSS VersionCSS1

Indent the first line of a <div> element with 50 pixels:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<div id="myDiv" style="text-indent:3cm;">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div><br>

<button type="button" onclick="myFunction()">Return text indentation of div</button>

<script>
function myFunction() {/*from w  w  w .jav  a  2  s  .c o m*/
    document.getElementById("myDiv").style.textIndent = '50px';
}
</script>

</body>
</html>

Related Tutorials