Javascript DOM CSS Style fontStyle Property

Introduction

Set the font for a <p> element to "italic":

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP">This is a paragraph.</p>

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

<script>
function myFunction() {//from w  w  w  . j av  a 2  s  .  co  m
  document.getElementById("myP").style.fontStyle = "italic";
}
</script>

</body>
</html>

The fontStyle property sets or gets whether the style of the font is normal, italic or oblique.

Property Values

Value Description
normal Font is normal. default
italic Font is in italic
oblique Font is in oblique
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The fontStyle property returns a String representing the font style of the text in the element.




PreviousNext

Related