Set the font size for a <p> element to "xx-large":
document.getElementById("myP").style.fontSize = "xx-large";
<!DOCTYPE html> <html> <body> <p id="myP">This is a paragraph.</p> <button type="button" onclick="myFunction()">Set font size</button> <script> function myFunction() {//w ww . j av a 2 s .com document.getElementById("myP").style.fontSize = "xx-large"; } </script> </body> </html>
The fontSize property sets or gets the font size of the text.
Property Values
Value | Description |
---|---|
xx-small x-small small medium large x-large xx-large | Sets the size of the font to different fixed sizes, from xx-small to xx-large |
smaller | Decreases the font-size by one relative unit |
larger | Increases the font-size by one relative unit |
length | Defines the font-size in length units |
% | Sets the font-size to a % of the parent element's font size |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The fontSize property Default Value: medium
The fontSize property returns a String representing the font size of the text in the element.