Style fontSize attribute
- Föregående sida fontFamily
- Nästa sida fontStyle
- Gå tillbaka till föregående nivå HTML DOM Style-objekt
Definition and usage
fontSize
Property to set or return the font size of the text.
See also:
CSS Tutorial:CSS teckensnitt
CSS Reference Manual:font-size attribute
HTML DOM Reference Manual:Font attribute
Example
Example 1
Set the font size of the <p> element to "xx-large":
document.getElementById("myP").style.fontSize = "xx-large";
Example 2
Demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text; document.getElementById("myP").style.fontSize = listValue;
Example 3
Return the font size of the <p> element:
alert(document.getElementById("myP").style.fontSize);
Syntax
Return fontSize property:
object.style.fontSize
Set fontSize property:
object.style.fontSize = "value|initial|inherit"
Attribute value
Value | Description |
---|---|
|
Set the font size to a different fixed size, from xx-small to xx-large. |
smaller | Decrease the font size by a relative unit. |
larger | Increase the font size by a relative unit. |
length | Define the font size by length unit. |
% | Set the font size to a percentage of the parent element's font size. |
initial | Set this property to its default value. See initial. |
inherit | Inherit this property from its parent element. See inherit. |
Technical details
Default value: | medium |
---|---|
Return value: | String that represents the font size of the element's text. |
CSS version: | CSS1 |
Webbläsarstöd
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Stöd | Stöd | Stöd | Stöd | Stöd |
- Föregående sida fontFamily
- Nästa sida fontStyle
- Gå tillbaka till föregående nivå HTML DOM Style-objekt