The textIndent
property sets or gets the indentation of the first line of text.
textIndent |
Yes | Yes | Yes | Yes | Yes |
Return the textIndent property:
var v = object.style.textIndent
Set the textIndent property:
object.style.textIndent='length|%|initial|inherit
Value | Description |
---|---|
length | Default to 0. Set the indentation in length units. |
% | Set the indentation in percent of the width of the container element |
initial | Set to default value. |
inherit | Inherit from its parent element. |
Default Value: | 0 |
---|---|
Return Value: | A string representing the indentation of the first line |
CSS Version | CSS1 |
The following code shows how to indent the first line with 50 pixels.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . j a va 2s. c om-->
<div id="myDiv">
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()">test</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.textIndent = "50px";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the text indentation.
<!DOCTYPE html>
<html>
<body>
<!-- w w w .j a va2s . c o m-->
<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()">test</button>
<script>
function myFunction() {
console.log(document.getElementById("myDiv").style.textIndent);
}
</script>
</body>
</html>
The code above is rendered as follows: