fontFamily style property
Specifies or returns the font face for text.
The fontFamily property is a comma separated list of font family names.
There are generic family names and others.
The generic family names are supported by all browsers on all platforms, other family names are not necessarily.
If you specify more than one font family, the browser will use the first from left to right that can be recognized.
For that reason, always use a generic family name at the last position of the fonts.
Family names containing whitespace must be quoted!
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: font-family |
Possible values:
The type of this property is string.
One of the following values: | ||||||||||||||||||
|
Description of values:
Some cursive fonts: Adobe Poetica, Caflisch Script, Sanvito, ... | |||||||
Some fantasy fonts: Alpha Geometrique, Critter, Cottonwood, ... | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Some monospace fonts: Courier, MS Courier New, Prestige, ... | |||||||
for example: Arial, Tahoma, 'Times New Roman', Verdana, -moz-fixed, ... | |||||||
Some sans-serif fonts: MS Arial, MS Tahoma, MS Verdana, Helvetica, ... | |||||||
Some serif fonts: Times New Roman, MS Georgia, Bodoni, Garamond, ... |
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the font-family property:
|
||||
<head> <style> .example1 { font-family: Tahoma, Verdana, serif; } .example2 { font-family: Verdana, "Times New Roman", sans-serif; } </style> </head> <body> <span class="example1">font-family: Tahoma, Verdana, serif;</span> <br /> <span class="example2">font-family: Verdana, "Times New Roman", sans-serif;</span> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the fontFamily property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeFont (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the selected options values var selectState = selectTag.options[whichSelected].text; var fontTest = document.getElementById ("fontTest"); fontTest.style.fontFamily = selectState; } </script> </head> <body> <span id="fontTest"> Sample multiline text <br />change it! </span> <br /> <select onchange="ChangeFont (this);" size="7"> <option />gill <option />helvetica <option />cursive <option />fantasy <option selected="selected" />serif <option />sans-serif <option />monospace </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, basefont, bdo, big, blink, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, html, i, input:button, input:file, input:password, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
color
font
fontSize
fontSizeAdjust
fontStyle
fontVariant
fontWeight
textAlign
textAlignLast
textAutospace
textDecoration
textIndent
textJustify
textKashidaSpace
textOverflow
textShadow
textTransform
textUnderlinePosition
font
fontSize
fontSizeAdjust
fontStyle
fontVariant
fontWeight
textAlign
textAlignLast
textAutospace
textDecoration
textIndent
textJustify
textKashidaSpace
textOverflow
textShadow
textTransform
textUnderlinePosition
External links:
font-family (MSDN)
font-family (Mozilla Developer Center)
font-family (Safari Reference Library)
font-family (W3C)
font-family (Mozilla Developer Center)
font-family (Safari Reference Library)
font-family (W3C)
User Contributed Comments