
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to set the font size of text with JavaScript?
To set the font size, use the fontSize property in JavaScript. You can try to run the following code to set the font size of the text with JavaScript −
Example
Live Demo<!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p id = "myID"> This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. </p> <button type = "button" onclick = "display()">Set Font Family and Size</button> <script> function display() { document.getElementById("myID").style.fontFamily = "verdana,sans-serif"; document.getElementById("myID").style.fontSize = "smaller"; } </script> </body> </html>
- Related Articles
- How to set the font family for text with JavaScript?
- How to set the font size of a Tkinter Canvas text item?
- How to change the font size of a text using JavaScript?
- Set the font size with CSS
- How to set the boldness of the font with JavaScript?
- How to increase the font size of a Text widget?
- How to change the font size of Text using FabricJS?
- How to set the size of subscript with Text using FabricJS?
- How to set the size of superscript with Text using FabricJS?
- How to set the font size of Matplotlib axis Legend?
- How to increase the font size of text in Arduino IDE?
- How to set font for text in JTextPane with Java?
- How to set font face, style, size and color for JTextPane text in Java
- Set Font Size with Pixels using CSS
- Set Font Size with em using CSS

Advertisements