CSS Fonts - CSS

What are CSS FONTS?

In this chapter, you will learn how to set fonts of a content, available in an HTML element. You can set following font properties of an element −

  • The font family of a text is set with the font-family property.

The font-family property should hold several font names as a "fallback" system. If the browser does not support the first font, it tries the next font, and so on.

  • The font-style property is mostly used to specify italic text.

This property has three values:

  • normal - The text is shown normally
  • italic - The text is shown in italics
  • oblique - The text is "leaning" (oblique is very similar to italic, but less supported)
  • The font-variant property specifies whether or not a text should be displayed in a small-caps font.

In a small-caps font, all lowercase letters are converted to uppercase letters. However, the converted uppercase letters appears in a smaller font size than the original uppercase letters in the text.

  • The font-weight property specifies the weight of a font:
  • The font-size property sets the size of the text.

Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs.

Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs.
The font-size value can be an absolute, or relative size.
Absolute size:
  • Sets the text to a specified size
  • Does not allow a user to change the text size in all browsers (bad for accessibility reasons)
  • Absolute size is useful when the physical size of the output is known.

Relative size:

  • Sets the size relative to surrounding elements
  • Allows a user to change the text size in browsers
  • The font property is used as shorthand to specify a number of other font properties.

How to Set the Font Family?

Below is the example, which illustrates how to set the font family of an element. Font family value can take up any font family name.

It will produce the following result −

CSS fonts outline

How to Set the Font Style?

Below is the example, which demonstrates how to set the font style of an element. Font style values can take up Italic, Normal and oblique.

It will produce the following result −

CSS fonts outline

How to Set the Font Variant?

Below example demonstrates how to set the font variant of an element. Font variant values can take up normal and small-caps.

It will produce the following result −

CSS fonts outline

How to Set the Font Weight?

Below example demonstrates how to set the font weight of an element. The functionality to specify how bold a font should be, is provided by font weight property. Possible values could be bold, bolder, lighter, normal, 100, 200, 300, 400, 500, 600, 700, 800, 900.

It will produce the following result −

CSS fonts outline

How to Set the Font Size?

Below example illustrates how to ssign the font size of an element. To control the size of fonts, the font size property is used. Font size can take any of these values: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, size in pixels or in %.

It will produce the following result −

CSS fonts outline

How to Set the Font Size Adjust?

Below example illustrates how to assign the font size adjust of an element. This property lets you to adjust the x-height to make fonts more special. Font size can take up any number.

It will produce the following output −

CSS fonts outline

How to Set the Font Stretch?

Below example illustrates how to set the font width of an element. This property relies mainly on the user's computer to have an expanded or condensed version of the font which is being used.

Possible values could be normal, wider, ultra-condensed, semi-condensed, condensed, extra-condensed, extra-expanded, expanded, semi-expanded, ultra-expanded.

It will produce the following result −

CSS fonts outline

What is Shorthand Property?

Also you can use the font property to set all the font properties at once. For example −

It will produce the following result −

CSS fonts outline

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CSS Topics