fontSize Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:fontSize

Description

The fontSize property sets or gets the font size.

Property Values

ValueDescription
xx-small x-small small medium large x-large xx-large Sets the size of the font to different fixed sizes, from xx-small to xx-large
smaller Decreases the font-size by one relative unit
larger Increases the font-size by one relative unit
length Defines the font-size in length units
%Sets the font-size to a % of? the parent element's font size
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: medium
Return Value: A String, representing the font size of the text in the element
CSS VersionCSS1

Set the font size for a <p> element to "xx-large":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<button type="button" onclick="myFunction()">Adjust font size</button>

<script>
function myFunction() {//from   w w  w.  j a v a 2s  .  co m
    document.getElementById("myP").style.fontSize = "xx-large";
}
</script>

</body>
</html>

Related Tutorials