How to change font size in JavaScript?

To change font size in JavaScript, do this: element.style.fontSize = '10px'.

For example, if this is your element:

<div id="my-element">text</div>

You can change the font size like so:

document.getElementById('my-element').style.fontSize = '10px';

And you can do the same with the style attribute in HTML:

<div id="my-element" style="font-size: 10px">text</div>