How to set the font family for text with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To set the font family, use the fontFamily property in JavaScript.

Example

You can try to run the following code to set the font family for text with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <h1>Heading 1</h1>
      <p id="myID">
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </p>
      <button type="button" onclick="display()">Set Font Family</button>
      <script>
         function display() {
            document.getElementById("myID").style.fontFamily = "verdana,sans-serif";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 15:52:54
Advertisements