Style fontSize Property
Example
Set the font size of an element to "x-large":
document.getElementById("demo").style.fontSize = "x-large";
Try it Yourself »
Definition and Usage
The fontSize property sets or returns the font size of the text.
Browser Support
Property | |||||
---|---|---|---|---|---|
fontSize | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the fontSize property:
object.style.fontSize
Set the fontSize property:
object.style.fontSize = "value|initial|inherit"
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. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | medium |
---|---|
Return Value: | A String, representing the font size of the text in the element |
CSS Version | CSS1 |
More Examples
Example
A demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("demo").style.fontSize = listValue;
Try it Yourself »
Example
Return the font size of an element:
alert(document.getElementById("demo").style.fontSize);
Try it Yourself »
Related Pages
CSS tutorial: CSS Font
CSS reference: font-size property
HTML DOM reference: font property
❮ Style Object