HTML | DOM Style textIndent Property

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                     

chevron_right


Output:

  • Before clicking on the button :
  • After clicking on button :

Example-2: To get the value of text-indent.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                     

chevron_right


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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : shubham_singh



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.