Skip to content
Related Articles

Related Articles

HTML | DOM Style textIndent Property
  • Last Updated : 04 Oct, 2019

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:




<!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 to change the textIndent to 120px from 40px-->
     <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.




<!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
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :