Easy Tutorial
❮ Coll Doc Forms Prop Select Selectedindex ❯

Style fontFamily Property


Definition and Usage

The fontFamily property sets or returns a list of font family names/generic font family names for the text content of an element.

The browser will use the first value it recognizes.

There are two types of font family values:

Tip: Always specify a generic font family name as a last choice!

Note: If the font family name contains spaces, enclose it in quotes.

Tip: Check out Web Safe Fonts for common font combinations.

Syntax

Set the fontFamily property:

Return the fontFamily property:

Value Description
font1, font2, etc. A list of font family names/generic font family names, separated by commas.
inherit The value of the fontFamily property is inherited from the parent element.

Browser Support

All major browsers support the fontFamily property.

Note: IE7 and earlier versions do not support the "inherit" value. IE8 requires a !DOCTYPE to support "inherit". IE9 supports "inherit".


Example

Change the font of the text:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>tutorialpro.org(tutorialpro.org)</title> 
<script>
function displayResult(){
    document.getElementById("p1").style.fontFamily="Impact,Charcoal,sans-serif";
}
</script>
</head>
<body>

<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change Font</button>

</body>
</html>

❮ Coll Doc Forms Prop Select Selectedindex ❯