Return to Video

CSS font family

  • 0:00 - 0:05
    You've seen how to change the color and
    background color of text on the page.
  • 0:05 - 0:09
    But there's so much more that you can do
    with text and CSS.
  • 0:10 - 0:12
    To start off, let's change the font.
  • 0:13 - 0:16
    What's a font? You probably already know
    what one is, but you may
  • 0:16 - 0:17
    not know the word for it.
  • 0:17 - 0:20
    It's the style of the letters that make up the words.
  • 0:20 - 0:23
    It is whether the letters have flourishes
    on them, or how thick they are,
  • 0:23 - 0:25
    or if they look like they're written
    with an ink pen.
  • 0:26 - 0:30
    It'll be easier if I go ahead and
    change the font on this webpage.
  • 0:31 - 0:35
    I'll go to the CSS rule that selects
    all the paragraphs,
  • 0:36 - 0:38
    and add a `font-family` property here.
  • 0:42 - 0:44
    Do you see how the letters changed
    [once we did that]?
  • 0:44 - 0:46
    They look a little bit simpler now.
  • 0:47 - 0:52
    Now, let me change the `font-family`
    back by specifying `serif` instead.
  • 0:52 - 0:56
    Do you notice that the letters
    look a little more complex?
  • 0:56 - 1:00
    A 'serif' font is any font that has what
    looks like little 'feet' on the letters.
  • 1:00 - 1:04
    When we tell the browser to use a 'serif'
    `font-family`, it will use the default
  • 1:04 - 1:08
    serif font for the computer. Which is
    usually the 'Times New Roman' font.
  • 1:11 - 1:13
    I'm going to change it back again, to `sans-serif` [now].
  • 1:14 - 1:18
    The 'sans' comes from Latin and means
    'without.'
  • 1:18 - 1:22
    So a sans-serif font is one that doesn't
    have the little 'feet' on the letters.
  • 1:22 - 1:24
    That is why the letters look simpler.
  • 1:24 - 1:28
    When we tell the browser to use a
    sans-serif `font-family', it uses
  • 1:28 - 1:33
    the default sans-serif for that computer,
    which is usually 'Arial' or 'Helvetica'.
  • 1:33 - 1:38
    But, here is an important point: It'll
    pick the default font of whatever
  • 1:38 - 1:41
    computer the viewer is on, not the author.
  • 1:42 - 1:45
    So we may very well be seeing two
    different sans-serif fonts right now,
  • 1:45 - 1:48
    if your computer has a different default than mine.
  • 1:48 - 1:54
    Sometimes, that's okay, but other times
    I want the viewer of the webpage to see
  • 1:54 - 1:56
    it in exactly the same fonts as me.
  • 1:57 - 2:02
    In that case, I can specify the precise
    font name. For example, Helvetica.
  • 2:03 - 2:08
    This will work, as long as both you and
    me have Helvetica on our computers.
  • 2:08 - 2:13
    But not all computers have all the same
    fonts, and in that case the computer will
  • 2:13 - 2:14
    ignore the property entirely.
  • 2:15 - 2:20
    Luckily, CSS lets us specify a 'fallback'
    font-family, for backup, in case
  • 2:20 - 2:22
    a particular font doesn't exist on a
    computer.
  • 2:23 - 2:28
    You just add a comma after 'Helvetica',
    and then bring back `sans-serif` there.
  • 2:28 - 2:33
    Now, the computer will look for Helvetica,
    and if it can't find it, just use its
  • 2:33 - 2:34
    default `sans-serif` font.
  • 2:35 - 2:39
    Generally, whenever you specify a specific
    font name, like Helvetica, you should
  • 2:39 - 2:43
    always specify a backup family name as
    well.
  • 2:44 - 2:48
    Besides 'serif' and 'sans-serif' there are
    a couple other generic font-family
  • 2:48 - 2:49
    names we can use.
  • 2:50 - 2:57
    If we wanted our lyrics to look handwritten,
    we could specify `font-family: cursive`.
  • 2:58 - 3:04
    If we wanted the lyrics to be fancier, we
    could try the `fantasy` font family.
  • 3:05 - 3:08
    Or, what if we wanted them to look like
    they were written on a type writer?
  • 3:08 - 3:11
    We could specify the `monospace` font family.
  • 3:11 - 3:15
    The `monospace` font is fixed width,
    meaning that all of the letters take up
  • 3:15 - 3:16
    the exact same width.
  • 3:16 - 3:20
    And, in fact, you've seen a lot of monospace
    fonts here on Khanacademy,
  • 3:20 - 3:23
    because we always use monospace fonts
    for code editors.
  • 3:24 - 3:27
    That's because we want all of our code to
    line up, regardless of the letters in
  • 3:27 - 3:28
    the words.
  • 3:29 - 3:33
    Now that you know how to change the
    font family, use your power wisely.
  • 3:33 - 3:38
    If you want your page to look good, limit
    yourself to a few different families,
  • 3:38 - 3:40
    and come up with pairs of fonts that look
    good together.
Title:
CSS font family
Description:

more » « less
Video Language:
English
Duration:
03:49
Retired user edited English subtitles for CSS font family
Retired user edited English subtitles for CSS font family
Retired user edited English subtitles for CSS font family

English subtitles

Revisions