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.
1 2 3 4 5 6 |
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.
1 2 3 4 5 6 7 8 9 10 |
<script> 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"; } </script> <a onclick="resizeText(1)" />Increase font size<br/> <a onclick="resizeText(-1)" />Reduce font size<br/> |
Note:
You can change 0.2 value as you wish to multiplier.
Also you can change fontFamily, fontWeight, background, margin, padding,….. like css properties.