Style fontStyle attribute

Definition and usage

fontStyle The attribute sets or returns the font style as normal, italic, or oblique.

See also:

CSS Tutorial:Fonti ya CSS

CSS Reference Manual:font-style attribute

HTML DOM Reference Manual:font attribute

Instance

Example 1

Sets the font of the <p> element to "italic" (italic):

document.getElementById("myP").style.fontStyle = "italic";

Try it yourself

Example 2

Demonstration of possible values:

var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("myP").style.fontStyle = listValue;

Try it yourself

Example 3

Returns the font style of the <p> element:

alert(document.getElementById("myP").style.fontStyle);

Try it yourself

Syntax

Return fontStyle property:

object.style.fontStyle

Set fontStyle property:

object.style.fontStyle = "normal|italic|oblique|initial|inherit"

Attribute value

Value Description
normal Font is normal. Default.
italic Font is italic.
oblique Font slant.
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: normal
Return value: String that represents the font style of the text within an element.
CSS Version: CSS1

Mwongozo wa kusimamia

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Mwongozo Mwongozo Mwongozo Mwongozo Mwongozo