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

How to change the font size of a text using JavaScript?


This method causes a string to be displayed in the specified size as if it were in a <font size= "size"> tag.

Example

You can try to run the following code to change the font size of a text using JavaScript −

<html>
   <head>
      <title>JavaScript String fontsize() Method</title>
   </head>

   <body>
      <script>
         var str = new String("Demo Text");
         document.write(str.fontsize(10));
         alert(str.fontsize( 10 ));
      </script>
   </body>
</html>