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

JavascriptObject Oriented ProgrammingFront End Technology

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>
raja
Published on 27-Feb-2018 07:55:18
Advertisements