Style fontFamily attribute
- Προηγούμενη σελίδα font
- Επόμενη σελίδα fontSize
- Επιστροφή στο προηγούμενο επίπεδο Όντοτητα Style του HTML DOM
Definition and usage
fontFamily
Property sets or returns a list of font family (font-family) names and/or generic family (generic-family) names in the text of the element.
The browser will use the first value it can recognize.
There are two types of font-family values:
- font-family: The name of the font family, such as "verdana" or "arial"
- generic-family: The name of the generic font family, such as "serif" or "sans-serif"
Tip
Always specify the generic family name as the last choice!
Please separate each value with a comma.
If the font family name contains spaces, it must be enclosed in quotes.
See also Web Safe Fonts,to learn about common font combinations.
See also:
CSS Tutorial:Γραμματοσειρά CSS
CSS Reference Manual:font-family attribute
HTML DOM Reference Manual:font attribute
Instance
Example 1
Set the font of the <p> element:
document.getElementById("myP").style.fontFamily = "Impact,Charcoal,sans-serif";
Example 2
Demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text; document.getElementById("myP").style.fontFamily = listValue;
Example 3
Returns the font of the <p> element:
alert(document.getElementById("myP").style.fontFamily);
Syntax
Return fontFamily property:
object.style.fontFamily
Set fontFamily property:
object.style.fontFamily = "font1, font2...|initial|inherit"
Attribute value
Value | Description |
---|---|
font1, font2... | A comma-separated list of font family names and/or generic family names. |
initial | Sets this property to its default value. See also initial。 |
inherit | Inherits this property from its parent element. See also inherit。 |
Technical details
Default value: | Not specified |
---|---|
Return value: | 字符串,表示元素中文本的字体名称。 |
Έκδοση CSS: | CSS1 |
Υποστήριξη προγράμματος περιήγησης
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη |
- Προηγούμενη σελίδα font
- Επόμενη σελίδα fontSize
- Επιστροφή στο προηγούμενο επίπεδο Όντοτητα Style του HTML DOM