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

How to set the spacing between words in a text in JavaScript?


Use the wordSpacing property in JavaScript to set the spacing between words.

Example

You can try to run the following code to learn how to implement wordSpacing property −

<!DOCTYPE html>
   <html>
      <body>
         <p id = "pid">This is an example paragraph.</p>
         <button type = "button" id="btn" onclick = "display()">Set Space</button>
         <script>
            function display() {
               document.getElementById("pid").style.wordSpacing = "25px";
            }
         </script>
      </body>
</html>