How to Change Font Size in Java Script

Written by lysis
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Change Font Size in Java Script
You can change your font size using JavaScript. (font image by Pavel Vlasov from

JavaScript is a client-side programming language that many website designers use to manipulate layout, text and images on a Web page. JavaScript can be used to change the size of a font when the user clicks a button or when the page is loaded. This is helpful when you want to make some part of the Web page content stand out. To make the font larger, the content is wrapped in a "div" tag and the JavaScript code will make the font larger within that block of HTML.

Skill level:

Other People Are Reading


  1. 1

    Open your HTML page in a text editor. You can use a simple, plain text editor like Notepad to edit JavaScript, or you can use more advanced applications like Notepad++, Visual Studio and Dreamweaver.

  2. 2

    Wrap a div tag around the text you want to edit. This allows you to change the font size of a specific area in your Web page without distorting the layout with a global font size change. The code below creates a div named "myDiv": <div id="myDiv"> My website text </div>

  3. 3

    Create the JavaScript function. To change a font size in your div tag, you need to set the "fontsize" property. The code below changes the div's font size: function change Size() { document.getElementbyId("myDiv").font Size = "12px"; }

  4. 4

    Add a button to the page to let the user choose to change the font size. To add the button and call the new JavaScript function, use the code below: <input type="button" onClick="change Size()">

  5. 5

    Save the file and open the page in your Web browser. Test the new code by clicking the button. The font size increases in the div tag.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.