The CSS reference

"font-size" - css property (v. css 1)

  • To specify the font size of a text.
  • Initial value: medium
  • The property is inherited
  • HTML usage: all elements
  • Browsers that support the font-size - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible font-size values:

value Comments CSS
absolute-size A keyword representing an index to a table of font sizes computed and kept by the UA. Possible values are:
xx-small | x-small | small | medium | large | x-large | xx-large
1
relative-size A keyword is interpreted relative to the table of font sizes and the font size of the parent element. Possible values are:
larger | smaller
1
length With this you specify a positive value (it cannot be negative) for the size followed with a unit identifier. 1
percentage With this you specify a positive value (it cannot be negative) with a percentage. Refer to parent element's font size . 1
inherit Will inherit the value from parent specification. This property value is new with CSS 2. 2

Possible unit identifier:

unit identifier Comments CSS
em The relative unit 'em' is relative to the font size of the element itself. 1
ex The relative unit 'ex' is relative to the font size of the element itself. 1
px Pixels, relative to the viewing device 1
in inches -> 1 inch is equal to 2.54 centimeters. 1
cm centimeters. 1
mm millimeters. 1
pt points -> the points used by CSS2 are equal to 1/72th of an inch. 1
pc picas -> 1 pica is equal to 12 points. 1

Property "font-size" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <style type="text/css">
      div {border: blue 1px solid; color:black;
           padding: 4px 4px 4px 4px; width: 400px;
      }
      .absolute { font-size: x-large; }
      .relative { font-size: larger; }
      .length { font-size: 24px; }
      .percentage { font-size: 140%; }
    </style>
  </head>
  <body style="font-size: 14px;" >
    <br>Starting with 14px
    <br>absolute-> font-size: x-large; <br>
    <div class="absolute" >
      A keyword representing an index to a
      table of font sizes computed and kept by the UA.
    </div>
    <br>relative-> font-size: larger;<br>
    <div class="relative" >
      A keyword is interpreted relative to the table
      of font sizes and the font size of the parent element.
    </div>
    <br>font-size: 24px;<br>
    <div class="length" >
      With this you specify a positive value for
      the size followed with a unit identifier.
    </div>
    <br>font-size: 140%;<br>
    <div class="percentage" >
      With this you specify a positive value with
      a percentage. It is related to the present font.
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.fontSize="font-size values"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:
var value=cStyle.fontSize;
// IE and Opera will return a value in units as used with a Set.
// Firefox will return a calculated float value in pixel (px).
// Chrome or Safari will return a calculated int value in pixel (px).
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.