CSS Fonts

Fonts are a set of characters (letters, numbers, and symbols) that share a common design. They are used to display text on a website. Choosing the right font for a website can have a big impact on its overall design and readability.

When choosing a font for a website, there are a few things to consider:

  • Legibility: The font should be easy to read, with clear letter shapes and good contrast between the letters and the background.
  • Branding: The font should align with the overall brand and style of the website.
  • Web-friendliness: The font should be available in a web-friendly format, such as web-font, which allows the font to be used on a website.
  • Performance: Consider the performance of the font, as some fonts can slow down the loading time of a website.
  • Popularity: Popular fonts are widely supported across different browsers, which ensures that your website will look consistent across different devices.

Once you have considered these factors, you can then choose a font that meets your needs and enhances the design of your website.

Generic Font Families

There are five generic font families that are supported by web browsers:


Serif fonts have small lines or flourishes at the end of the strokes that make up the letters. Examples of serif fonts include Times New Roman, Georgia, and Garamond.


Sans-serif fonts do not have the small lines or flourishes at the end of the strokes. Examples of sans-serif fonts include Arial, Verdana, and Helvetica.


Monospace fonts have the same width for all characters. Examples of monospace fonts include Courier and Lucida Console.


Cursive fonts are designed to look like handwriting. Examples of cursive fonts include Brush Script and Lucida Handwriting.


Fantasy fonts are decorative and are not meant to be used for long blocks of text. Examples of fantasy fonts include Western and Grilled Cheese.

When using generic font family, it's important to keep in mind that they are not guaranteed to have the same appearance across different devices and browsers.

CSS font-family Property

The CSS font-family property is used to specify the font for an element. It allows you to set a specific font for text, or to use a generic font family if the specific font is not available.

The font-family property is used in the following format:

font-family: font-name, font-name, generic-font-name;

font-name is the name of a specific font, such as Arial or Times New Roman. If a specific font is not available on the user's device, the browser will try to use the next font in the list.

generic-font-name is the name of a generic font family, such as serif, sans-serif, monospace, cursive or fantasy.


body {
    font-family: Arial, Helvetica, sans-serif;

This tells the browser to use the Arial font if it's available, or the Helvetica font if Arial is not available. If neither Arial nor Helvetica are available, the browser will use any other available sans-serif font.

It's also possible to use webfonts using @font-face to import the font and then use it with font-family property.

It's important to note that the font-family property will only affect text inside the element to which it's applied, and it can be inherited by child elements.

You can also use font property to set font-size, font-weight, font-style, font-stretch and line-height properties in one line of CSS.

The Difference Between Serif and Sans-serif Fonts

The main difference between serif and sans-serif fonts is the small lines or flourishes that are found at the end of the strokes that make up the letters in serif fonts. These lines are called serifs. Sans-serif fonts, as the name suggests, do not have these lines.

Serif fonts are considered to be more traditional and are often used in printed materials such as books and newspapers. They are believed to improve readability by making the text easier to scan, and are often used in print design.

Sans-serif fonts, on the other hand, are considered to be more modern and are often used in digital media such as websites and mobile apps. They are believed to be more legible on screens due to their simplicity and lack of serifs, which can make them appear fuzzy on low-resolution screens.

It's important to note that the choice between a serif and sans-serif font should be based on the specific use case and context of the design. A serif font might be a better choice for a book cover or a printed invitation, while a sans-serif font might be a better choice for a website or a mobile app.

In summary, serif fonts are more traditional and are often used in print design, while sans-serif fonts are more modern and are often used in digital media.

CSS Basics