Example
Set the font for a <p> element to "italic":
document.getElementById("myP").style.fontStyle = "italic";
Try it Yourself »
Definition and Usage
The fontStyle property sets or returns whether the style of the font is normal, italic or oblique.
Browser Support
The fontStyle property is supported in all major browsers.
Syntax
Return the fontStyle property:
object.style.fontStyle
Set the fontStyle property:
object.style.fontStyle="normal|italic|oblique|initial|inherit"
Property Values
Value | Description |
---|---|
normal | Font is normal. This is default |
italic | Font is in italic |
oblique | Font is in oblique |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | normal |
---|---|
Return Value: | A String, representing the font style of the text in the element |
CSS Version | CSS1 |
More Examples
Example
A demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("myP").style.fontStyle = listValue;
Try it Yourself »
Example
Return the font style of a <p> element:
alert(document.getElementById("myP").style.fontStyle);
Try it Yourself »
Related Pages
CSS tutorial: CSS Font
CSS reference: font-style property
HTML DOM reference: font property
< Style Object