font Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:font

Description

The font property sets or gets six separate font properties in a shorthand form:

  • font-style
  • font-variant
  • font-weight
  • font-size
  • line-height
  • font-family

Property Values

Value Description
style font-style
variant text in a small-caps font
weightboldness of the font
size size of the font
lineHeightdistance between lines
familyfont face
caption The font used for captioned controls (like buttons, drop-downs, etc.)
icon The font used to label icons
menu The font used in menus
message-box The font used in dialog boxes
small-caption The font used in small controls
status-barThe font used in window status bars
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: not specified
Return Value: A String, representing different font properties of the element
CSS VersionCSS1

Get the font for a <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-weight:bold">This is a paragraph.</p>

<button type="button" onclick="myFunction()">Return font weight</button>

<script>
function myFunction() {/*w  w w .j  a va 2  s.c o  m*/
    console.log(document.getElementById("myP").style.fontWeight);
}
</script>

</body>
</html>

Related Tutorials