HTML | DOM Style textIndent Property
Last Updated :
13 Jul, 2022
The DOM Style textIndent Property is used for indentation of the first line in each block of text. It also takes negative values. If the value is negative then the first line will be indented to the left.
Syntax:
- It is used to set the textIndent property:
object.style.textIndent = "length|%|initial|inherit"
- It is used to get the textIndent property:
object.style.textIndent
Properties:
- length: It is used to set fixed indentation in terms of px, pt, cm, em etc. The default value of length is 0.
- percentage (%): It is used to define the indentation in % as compared to the width of the element.
- initial: It is used to set text-indent property to its default value.
Return Value: It returns a string value which represent the indentation of the first line in each block of text.
Examples:
html
<!DOCTYPE html>
< html >
< head >
< title >
DOM Style text-indent Property
</ title >
< style >
#sudo {
text-indent: 40px;
}
</ style >
</ head >
< body >
< h1 style = "color:green;">GeeksforGeeks</ h1 >
< h2 >DOM Style text-indent Property</ h2 >
< h2 >text-indent: 40px:</ h2 >
< div id = "sudo">
Prepare for the Recruitment drive of product
based companies like Microsoft, Amazon, Adobe
etc with a free online placement preparation
course. The course focuses on various MCQ's
& Coding question likely to be asked in the
interviews & make your upcoming placement
season efficient and successful.
</ div >
< button type="button" onclick="myGeeks()">Submit</ button >
< script >
function myGeeks() {
document.getElementById("sudo").style.textIndent = "120px";
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking on the button :
- After clicking on button :
Example-2: To get the value of text-indent.
html
<!DOCTYPE html>
< html >
< head >
< title >
DOM Style text-indent Property
</ title >
</ head >
< body >
< h1 style = "color:green;">GeeksforGeeks</ h1 >
< h2 >DOM Style text-indent Property</ h2 >
< div id = "sudo" style="text-indent:100px;">
Prepare for the Recruitment drive of product
based companies like Microsoft, Amazon, Adobe
etc with a free online placement preparation
course. The course focuses on various MCQ's
& Coding question likely to be asked in the
interviews & make your upcoming placement
season efficient and successful.
</ div >
< button type="button" onclick="myGeeks()">Submit</ button >
< script >
function myGeeks() {
alert(document.getElementById("sudo").style.textIndent);
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking on the button:
- After clicking on the button:
Supported Browser: The browser supported by DOM Style textIndent are listed below:
- Google Chrome 1
- Edge 12
- Internet Explorer 3
- Firefox 1
- Opera 3.5
- Safari 1
Share your thoughts in the comments
Please Login to comment...