Style fontSizeProperty
Style Object
Definition and Usage
The fontSize property sets or returns the font size of the text.
Syntax
Set the fontSize property:
Object.style.fontSize="value|inherit"
Return the fontSize property:
Object.style.fontSize
| Value | Description |
|---|---|
| xx-small x-small small medium large x-large xx-large |
Sets the font size to a different fixed size, 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 using units such as px, cm, etc. |
| % | Defines the font size as a percentage of the font size of the parent element. |
| inherit | The value of the fontSize property is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the fontSize property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Change the font size of the text:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSize="xx-large";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font size</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSize="xx-large";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font size</button>
</body>
</html>
Try it yourself »
Style Object Other Extensions