Categories of Typefaces
- Script: have a hand-lettered look and tend to be harder to read in small sizes, all caps, or long blocks of text.
- Decorative: Since decorative fonts tend to have big personalities, they too are usually reserved for headings and decorative details when used for the web.
- Monospace: each character uses the same amount of horizontal space. Each character is the same width. Often used for displaying code.
- Serif: distinguished by small, decorative lines, usually at the top or at the bottom of the letters.
- Sans-serif: tend to be viewed as traditional and formal. Sans-serif typefaces do not have decorative lines, and are often thought of as contemporary and modern.
Changing the font-family
Generic font-family Names
- serif (serif fonts)
- sans-serif (sans-serif fonts)
- cursive (script or decorative fonts)
- fantasy (decorative fonts)
- monospace (monospace fonts)
Web-safe fonts: http://cssfontstack.com/
Font Weight
- 100 - Thin
- 200 - Extra Light (Ultra Light)
- 300 - Light
- 400 - Normal
- 500 - Medium
- 600 - Semi Bold (Demi Bold)
- 700 - Bold
- 800 - Extra Bold (Ultra Bold)
- 900 - Black (Heavy)
- Normal is equal to 400 and is also the default for body text
- Bold is equal to 700 and is the default for headings
Font Style
Used to add or remove an italic style. There are three values: italic, oblique, and normal.
Web Fonts
- Downloaded font files
- Included in your project files just like other files (i.e. images)
- Declare and link to font files using
@font-face
URL of the font
Cross-browser Compatibility
Font Size
font-size: px, em, rem
- Different units for specifying the font size
- Relative values are calculated based on the nearest ancestor element
- Absolute values are fixed and not affected by ancestor elements
font-size: px
- Screens are measured in pixels
- Absolute value, great for accuracy
- Use whole numbers, avoid decimals
- Browser default = 16px
font-size: em
- Named after the letter “m”
- Relative unit
- Can use whole numbers or decimal points
- 1em = inherited font-size
font-size: rem
- root em
- Relative unit
- Only relative to the root element (
<html>
) - Not affected by parent or ancestor elements
Font shorthand
- font-style
- font-size
- font-weight
- font-family
- font-variant
- line-height
Note:
- Must include values for the font-size and font-family
- May optionally include values for font-style, font-variant, font-weight, and line-height
- Order matters! font-style, font-variant, and font-weight must precede font-size
- font-variant = normal or small-caps only
- font-size/line-height
- font-family must be the last value specified
text-decoration
text-align
- The text-align property can be used to align content within a block element
- Add it to the HTML element itself or the parent element
line-height
- The line-height property sets the height of the space between two lines of text
- Closely related to font-size
- Can use different value types (px, %, ems, rems, or unitless)
text-transform
- The text-transform CSS property specifies how to capitalize an element’s text.
- It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.