Dev Corner

Software Developer’s Notepad

We can specify the font, with which the text to be displayed. This made using the property font-family. Then we have to assign a value to this property.

p{
    font-family: "Times New Roman";
}

Discussion

As well as specific fonts, such as Times New Roman or Tahoma, CSS allows the use of some more generic font families, which are:

  • serif
  • sans-serif
  • monospace
  • cursive
  • fantasy

When we specify fonts, we should not forget that there is a possibility that the user doesn’t have the defined font installed on its computer. If we define a font and it happens that the user does not have, then the text will be displayed with the default Web browser’s font.

We can simply use generic font names and let user’s systems to decide which font to apply. If we want the document to look like it uses Arial (sans-serif font) for example, then we could use the following code:

p{
    font-family: sans-serif;
}

It could be used also more complex declarations. Then the first font will be used, but if it is not available then the second font will be used. So there is a reason to make the last font a generic, which we will be used at any case.

p{
    font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
}

Add A Comment

You must be logged in to post a comment.