Computer >> Computer tutorials >  >> Programming >> Javascript

How to set the indentation of the first line of text with JavaScript?


To set the indentation, use the textIndent property.

Example

You can try to run the following code to return the indentation of the first line of text with JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <div id = "myText">
         This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text.
      </div>
      <br>

      <button onclick = "display()">Set Text Indent</button>
      <script>
         function display() {
            document.getElementById("myText").style.textIndent = "50px";
         }
      </script>
   </body>
</html>