In this short JavaScript tutorial, Nurani guides you how to use JavaScript in changing the web page's font size. Maybe the JavaScripts to change font size are not new things on jsB@nk, because we shared you a lot of JavaScript codes, tutorials for things such as increase font size, javascript font style, javascript text size, ... But this JavaScript tutorial is also good practice to study, let go to the full post-page for details.
- Demo
- Enlarge
- Reload
- New window
Free iPage Web Hosting for First Year NOW
If you're still looking for a reliable web host provider with affordable rates, why you don't take a little of time to try iPage, only with $1.89/month, included $500+ Free Extra Credits for the payment of 24 months ($45)?
Over 1,000,000+ existisng customers can not be wrong, definitely you're not, too! More important, when you register the web hosting at iPage through our link, we're going to be happy for resending a full refund to you. That's awesome! You should try iPage web hosting for FREE now! And contact us for anything you need to know about iPage.
Actually, almost all browsers have a feature to control the characters on the web pages you visit, by pressing the Ctrl key together with + (to zoom in) or - (to zoom out). But there is one other way of adding such a function "dynamic font size" on your site using javascript.
Here is a script that can be used to facilitate the visitors to
control the font size of text on each page of your website/blog. This
will be very useful for readers who struggle with small letters, and
allow the person to enlarge the font size of your writing, so they are
easier to read.
<script type="text/javascript"> var min=8; var max=18; function zoominLetter() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=max) { s += 1; } p[i].style.fontSize = s+"px" } } function zoomoutLetter() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=min) { s -= 1; } p[i].style.fontSize = s+"px" } } </script>
The script above will change the font size of text within the paragraph (tag <p>). If you want to use another tag, you can change the getElementsByTagName('p');
Of course, this script only works on the page with pixel sized fonts (letter-sized pixels (px)) compared with relative sized fonts (the relative size of the letters like: "em" and "%"). In addition, if the script does not find the font size of a paragraph, it will use the standard size, which is 12px.
How To Use :
Enter the above script on your blog page (either by typing in the tag <head> or by using .js file external and import). To call the function zoominLetter and zoomoutLetter you can use the following HTML code:
<a href="/javascript/article/Using_JavaScript_to_Change_Your_Web_Page_Font_Size.php/javascript:zoominLetter();">A</a> <a href="/javascript/article/Using_JavaScript_to_Change_Your_Web_Page_Font_Size.php/javascript:zoomoutLetter();">a</a>
tips: You can change the text A | a with other signs, or replace it with a picture by using tags <img>.
- Sent (0)
- New
Generate your business videos by AI with voice or just text
chatGPTaz.com
Talk to ChatGPT by your mother language
AppAIVideo
Your first FREE AI Video App
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Faceswap AI Online
Swap Faces Video, Photo & GIFs Instantly with Powerful AI Tools - Faceswap AI Online FREE
Faceswap AI Online
Swap Faces Video, Photo & GIFs Instantly with Powerful AI Tools - Faceswap AI Online FREE
Temu Free $500 for New Users
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Free TikTok Ads Credit
Master TikTok Ads for Your Business Marketing
Dall-E-OpenAI.com
Generate creative images automatically with AI
chatGPT4.win
Talk to ChatGPT by your mother language
First AI Product from Elon Musk - Grok/UN.com
Speak to Grok AI Chatbot with Your Language
Tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools
GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project
iPhoneKer.com
Save up to 630$ when buy new iPhone 16
Buy Tesla Optimus Robot
Order Your Tesla Bot: Optimus Gen 2 Robot Today for less than $20k
Reply
Reply
Reply
Great Code Reply
Change Text Size based on html tag id? Reply
perhaps yes @ Aswad Reply