Web Development

Dr Derek Bridge
School of Computer Science & Information Technology
University College Cork

Lecture Objectives

  • learn about CSS text properties
  • learn about CSS font properties
  • learn how to use downloadable fonts

Text Formatting

Multicolumn Text

A large quantity of text might look better if the text is laid out in columns, like in a newspaper.

In CSS, on the container, specify column-width, e.g.:
column-width: 20em;
You get as many 20em columns as will fit.

Multicolumn Text Example

Hyphenation

What can we do if a word is too long for its column?

  • Either:
    • CSS: set hyphens: manual on the container;
    • HTML: put ­ inside the word at possible places where it can be hyphenated.
  • Or:
    • CSS: set hyphens: auto on the container;
    • HTML: make sure the container has (or inherits) a lang attribute.

Font Properties

There are various font properties, e.g.


p {
    font-family: "Times New Roman";
    font-size: 12px;
    font-style: italic;
    font-weight: bold;
}

Fonts

Some fonts are proportional;
others are monospace.

Some fonts have serifs;
others are sans-serif.

Fonts on the Web

  • You do not know what fonts will be available on your user's machine:
    • different platforms come with different fonts installed;
    • many software packages install further fonts.

Font Families

  • Use the font-family property but give it multiple values (a font stack) to cover multiple platforms, e.g.:
    
    body {
        font-family: Verdana, Geneva, Tahoma, sans-serif;
    }
  • First give the ideal font, then some good alternatives, then some common alternatives, then a generic.
  • The generics are: serif, sans-serif, cursive, fantasy and monospace.

Downloadable Fonts

CSS has downloadable fonts.
Use the @font-face @rule, e.g.


@font-face {
    font-family: MuseoSans;
    src: url('fonts/museosans-500-webfont.woff2') format('woff2');
}
    
body {
    font-family: MuseoSans, Verdana, Geneva, Tahoma, sans-serif;
}
    

The browser requests the museosans-500-webfont.woff2 file from the URL.

Choosing Fonts

Think about copyright!

Think about readability!

Free Fonts!

You can download font files from
https://fontlibrary.org/
https://fonts.google.com/

FOUT and FOIT

  • These fonts must be fetched by clients before they can be used.
  • Browsers have adopted two approaches:
Flash Of Unstyled Text (FOUT) Flash Of Invisible Text (FOIT)
the user first sees one of the fallback fonts then, after a delay, the font changes to the downloaded one the user first sees no text then, after a delay, the text appears using the downloaded font

G'luck!