fontFamily Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:fontFamily

Description

The fontFamily property sets or gets a list of font-family names and/or generic-family names for text.

font-family: The name of a font-family, like "verdana" or "arial"

generic-family: The name of a generic font-family, like "serif" or "sans-serif"

Separate each value with a comma. If a font-family name contains whitespace, it must be quoted.

Property Values

Value Description
font1, font2, etc. A comma-separated list of font-family names and/or generic-family names
initialSets this property to its default value.
inheritInherits this property from its parent element.

Technical Details

Item Value
Default Value: not specified
Return Value: A String, representing the font name of the text in the element
CSS VersionCSS1

Get the font for a <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-family:Arial,Helvetica,sans-serif;">This is a paragraph, shown in the Arial font.</p>

<button type="button" onclick="myFunction()">Return font</button>

<script>
function myFunction() {/*  w w  w .  j a va2s .c  om*/
    console.log(document.getElementById("myP").style.fontFamily);
}
</script>

</body>
</html>

Related Tutorials