Latest web development tutorials

HTML DOM Style fontSize property

Style Object Reference Style Objects

Definition and Usage

fontSize property sets or returns the text font size.

grammar

Setting fontSize properties:

Object.style.fontSize="value|inherit"

Back fontSize properties:

Object.style.fontSize

描述
xx-small
x-small
small
medium
large
x-large
xx-large
把字体的尺寸设置为不同的固定尺寸,从 xx-small 到 xx-large。
smaller 把字体尺寸减小一个相对单位。
larger 把字体尺寸增大一个相对单位。
length 使用 px、cm 等单位定义字体尺寸。
% 定义字体尺寸为父元素字体尺寸的某个百分比。
inherit fontSize 属性的值从父元素继承。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support fontSize property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


Examples

Examples

Change the text font size:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.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"


Style Object Reference Style Objects