Javatpoint Logo
Javatpoint Logo

CSS font-family

HTML pages' look and formatting are specified using the language known as CSS (Cascading Style Sheets). The `font-family` property in CSS is used to specify the preferred font(s) for text content within an HTML element. The 'font-family' property is broken down into primary and advanced ideas here:

Basics Concepts of Font Family

1. Font Family Name: A font family name may be provided as a string value. For instance:

The browser will try to utilize the Arial font in this situation. If Arial isn't accessible, a standard sans-serif font will be used instead.

2. Generic Font Families: When typefaces are unavailable, one might fall back on one of five generic font families. The following generic families:

  • "Serif": Usually utilized in more formal or traditional material.
  • "Sans-serif": Frequently utilized for more contemporary and casual material.
  • "Monospace": Used to preserve character alignment or show code.
  • "cursive": Represents handwriting or typefaces that resemble script.
  • "Fantasy": This term refers to decorative or fantasy-style typefaces.

Advanced Concepts of Font Family

1. Font Stacks: If the specified font is unavailable, you may provide alternative font families. This is known as a font stack. For instance:

In this case, the browser will first attempt to apply the "Helvetica Neue" typeface. As such, it will try to utilize Arial; if possible, it will turn back on a standard sans-serif font.

2. System Fonts: The system typefaces pre-installed on a user's device may be used using CSS. You may instruct the browser to use the operating system's default font by providing the general name of the font family. For instance:

In this case, the browser will try to utilize the system's default fonts. It will utilize the Apple system typeface on Apple-branded devices, San Francisco on macOS, and Segoe UI on Windows.

3. Web Fonts: Custom fonts retrieved from a distant server rather than placed on the user's device are called web fonts. To import and utilize web fonts in your CSS, use the '@font-face' rule. For instance:

This example uses the '@font-face' syntax to import the "MyWebFont" web font, which is subsequently utilized in the 'font-family' property.

These are the fundamental concepts and more complex concepts around the 'font-family' property in CSS. One can manage the look and feel of the text on your websites by using several font families.

Types of a Font Family in CSS

There are five types or classifications of fonts are:

  1. Serif Fonts: Serif fonts include little artistic strokes or lines at the extremities of the letters, referred to as serifs. They are regarded as more formal and conventional and are often employed for body content in printed products. Georgia, Times New Roman, and Garamond are a few examples.
  2. Sans-serif Fonts: Sans-serif fonts lack serifs and have a more recent, clean look. They are frequently utilized for screen-based and digital entertainment. Arial, Helvetica, and Verdana are a few examples.
  3. Monospaced Fonts: Equal space is used between each letter in monospaced fonts, commonly called fixed-width fonts. Every letter takes up the same proportion of horizontal space as a result. They are often utilized in tabular data, terminal displays, and coding. Consolas, Monaco, and Courier are a few examples.
  4. Cursive Fonts: Cursive fonts imitate calligraphy or handwriting. They feature letterforms that flow together and seem handmade. Decorative or personal touches are often added to designs using cursive fonts, such as Lucida Handwriting, Zapfino, and Brush Script.
  5. Fantasy Fonts: Typefaces with beautiful and inventive flourishes are included in the category of fantasy fonts. They are frequently utilized for imaginative and artistic designs like logos, posters, and material with a fantastical theme. Unique and unusual letterforms may be seen in fantasy typefaces, integrating symbols or ornate motifs. Chiller, Jokerman, and Ravie are other examples.

These five font categories provide a range of styles and traits to accommodate various design objectives and aesthetics.


Next TopicCSS font-weight





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA