Skip to content Skip to sidebar Skip to footer

javascript resize text example

Reading Time: < 1 minute

How to change / resize page font using javascript.Check this demo and download javascript resize text example.For a example if you click button, then page font size will be increase and after click another button then reduce font size.

Following funtion is getting parameter as value of increase and then change the body font size.

function resizeText(val) {
  if (document.body.style.fontSize == "") {
    document.body.style.fontSize = "1.0em";
  }
  document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (val * 0.2) + "em";
}

How to use this function.


Increase font size
Reduce font size

Note:

You can change 0.2 value as you wish to multiplier.
Also you can change fontFamily, fontWeight, background, margin, padding,….. like css properties.
View Demo