To choose a font family for a Web page element use the style
where font1, font2, . . . are generic or specific values. Generic font names must be serif, sans-serif, monospace, cursive, or fantasy.
Here is how the generic fonts look installed on your computer look:
Generic names |
---|
This is SERIF serif This is SANS-SERIF sans-serif This is MONOSPACE monospace This is CURSIVE cursive This is FANTASY fantasy |
Specific fonts can be listed being separated by commas. The browser will scan these fonts in order and use whatever font is available.
Example:
<p style="font-family:Arial, Helvetica,
sans-serif"> this is a test paragraph</p> |
this is a test paragraph
To specify a font size for an element, use the style
The size can be measured in absolute units:
Absolute units | Comments |
---|---|
font-size : 0.5in font-size : 37pt font-size : 3pc font-size : 16px | size in inches points (1 inch = 72 points) picas (1 pica = 12 points) pixels (size depends on screen resolution) |
. . . or in relative units:
Relative units | Comments |
---|---|
font-size : 3em font-size : 2ex font-size : 150% | em unit (width of letter M) ex unit (height of letter x) percentage of the current font size |
. . . or absolute-size key words:
Relative units | Comments |
---|---|
font-size : xx-small font-size : x-small font-size : small font-size : medium font-size : large font-size : x-large font-size : xx-large |
xx-small x-small small medium large x-large xx-large |
The font size increases in a factor of 1.5 by default. Setup for the default font size for the body is small (it is medium in most IE browsers).
. . . or relative-size key words:
Each application of these key words moves the font size to the next category in order (if it exists).
These style elements specify the appearance of your font and its weight:
where weight is either a value from 100 (lightest) to 900 (heaviest) in intervals of 100, or one of the keywords normal, bold, lighter, or heavier.
Example (styling the <p> tag):
font-style : normal | font-style : italic | font-style : oblique |
---|---|---|
font style |
font style |
font style |
font-weight : 100 | font-weight : 200 | font-weight : 300 | font-weight : 400 | font-weight : 500 | font-weight : 600 | font-weight : 700 | font-weight : 800 | font-weight : 900 |
---|---|---|---|---|---|---|---|---|
font weight |
font weight |
font weight |
font weight |
font weight |
font weight |
font weight |
font weight |
font weight |
These style elements specify the horizontal space between individual letters and words, and vertical space between lines of text. To set these values use the following style:
Example (styling the <p> tag):
line-height : 3ex | letter-spacing : 2em |
---|---|
line |
letter spacing |
To align text horizontally, use the text-align attribute:
Example (styling the <td> tag):
text-align:center | text-align:right |
---|---|
text align | text align |
To align text vertically, use the vertical-align attribute:
The following table lists several examples for various values of the alignment attribute of the aligned text within the <i> tag:
Alignment | Result |
---|---|
vertical-align : baseline | Text aligned text |
vertical-align : middle | Text aligned text |
vertical-align : super | Text aligned text |
vertical-align : sub | Text aligned text |
vertical-align : bottom | Text aligned text |
vertical-align : text-bottom | Text aligned text |
vertical-align : top | Text aligned text |
vertical-align : text-top | Text aligned text |
These text properties are supported by the following CSS properties:
Example:
Style | Result |
---|---|
text-decoration : none | no decoration |
text-decoration : underline | underline |
text-decoration : overline | overline |
text-decoration : line-through | line-through |
The next set of properties support the transformation that will be applied to the text characters:
Examples:
Style | Result |
---|---|
<p style="text-transform:capitalize">capitalize first letter of each word</p> | capitalize first letter of each word |
<p style="text-transform:uppercase">display paragraph in upper-case</p> | display paragraph in upper-case |
<p style="text-transform:lowercase">DISPLAY ALL IN LOWER-CASE</p> | DISPLAY ALL IN LOWER-CASE |