Basic Font Properties
Specifying the Font Name
- font-family
Examples
- body { font-family: Arial; }
- var { font-family: Courier, monospace; }
- p { font-family: "Duru Sans", Verdana, sans-serif; }
Examples: Generic Font Families
- serif
- sans-serif
- monospace
- cursive
- fantasy
Specifying Font Size
- font-size
- Values: length unit, percentage, or size keywords.
Examples
- h1 {font-size: 1.5em; }
- h1 {font-size: 150%; }
- h1 {font-size: x-large; }
- strong {font-size: larger; }
Size Keyword Values
- xx-small
- x-small
- small
- medium, default
- large
- x-large
- xx-large
- smaller, relative to surrounding text
- default size
- larger, relative to surrounding text
Font Weight (Boldness)
- font-weight
- Most fonts don't have more than one bold weighting, so there will be no difference between using various bold values.
Examples:
- normal
- bold
- bolder
- lighter
- 100
- 200
- 300
- 400
- 500
- 600
- 700
- 800
- 900
- font-style
- This is essentially the option for italics. Though both 'italic' and 'oblique' are value options, they will usually be displayed exactly the same way.
Examples:
- normal
- italic
- oblique
Font Variant in CSS2.1 (Small Caps)
- font-variant
- The original font-variant property from CSS2.1 only had the effect of changing text into having 'small caps'. CSS3 has many new font-variant properties, but font-variant can still be used for small caps as well.
Examples:
- normal > "HEY! Listen, Link."
- small-caps > "HEY! Listen, Link."
Font Stretch (Condensed and Extended)
- font-stretch
- If a browser cannot find a font that includes a stretched or condensed version, it will not try to synthesize the difference.
Examples:
- ultra-condensed
- extra-condensed
- condensed
- semi-condensed
- normal
- semi-expanded
- expanded
- extra-expanded
- ultra-expanded
The Shortcut font Property
- font (shortcut property)
- The font property allows you to combine all the font properties into one line for convenience. Only the small-caps 'font-variant' can work with this property. The order of values is important for this property. A font property must include a font-size value and a font-family value in that order. However, aside from this, other properties can be placed in any order before the size property. Any omitted properties default to 'normal', NOT to the browser default properties. For example, heading elements are bold by the default browser style rules, but when 'reset' in a font property without being specified to be bold again, it will default to 'normal' and lose the bold property.
Font Syntax
selector{ font: style weight stretch variant size/line-height font-family; }
Examples:
- p {font: 1em sans-serif; }
- h1 {font: bold 1.5em Georgia, serif; }