HTML DOM Style fontSize Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

Style fontSize Property

❮ Style Object

Example

Set the font size for a <p> element to "xx-large":

document.getElementById("myP").style.fontSize = "xx-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("myP").style.fontSize = listValue;
Try it Yourself »

Example

Return the font size of a <p> element:

alert(document.getElementById("myP").style.fontSize);
Try it Yourself »

Related Pages

CSS tutorial: CSS Font

CSS reference: font-size property

HTML DOM reference: font property


❮ Style Object