CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination Font-Face in CSS CSS Two Classes CSS Type Not Equal CSS Display Grid CSS Fade Animation CSS Grid CSS Color Code CSS Selects All Children CSS Shapes CSS Stylesheet or Cheatsheet Button Disabled CSS Contact Form in HTML and CSS CSS Abbreviation CSS Align to the Bottom CSS Animation Fade-in CSS Margin vs Padding CSS Media Print CSS Tilde CSS Beautifier CSS Multiple Classes CSS Normalization CSS Not First Child CSS Portal CSS Pseudo Classes How to Make Align the Right Elements in CSS Image and Text Side by Side in CSS Root in CSS Free CSS com

Questions

What is Bootstrap CSS What is CSS used for How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language How to edit CSS in WordPress How to use google fonts in CSS How to create blinking text using CSS How to Set Space between the Flexbox Is CSS a Programming Language

Difference

Difference between HTML and CSS Grid Vs Flexbox in CSS Difference between CSS Grid and CSS Flexbox

Misc

Create a 3D text effect using HTML and CSS Hover condition for a:before and a:after in CSS Bem CSS Boder Types CSS Features of CSS Font Face CSS Image Overlay CSS CSS Responsive Design CSS Responsive Design CSS Scrollbar CSS Transform Code for Blue in CSS How to create circle in CSS? How to download font family? Box Model in CSS with Example CSS Background Image CSS Login CSS Object-Fit CSS Placeholder Color CSS Slider HTML CSS Projects Link CSS MDN CSS Movate CSS Crop CSS Font Shorthand How to Write CSS Responsive Code Live HTML CSS Code Editor Opacity CSS SCSS TO CSS

Font-Face in CSS

Custom fonts are defined by CSS and made available on our web pages via the @font-face rule. To style text components on a web page, web designers can use this rule to embed or link to font files. 

The user's device can install the custom font locally or fetch it from a distant server.

Overview

  1. We may use both local() and url() at the same time. The custom font from the distant server will be utilized as a backup if a local copy is not available and matches. 
  2. Because resources are loaded by browsers according to their declaration-list order, local() should be written before url(). 
  3. The methods url() and local() are both optional.
  4. A rule block is proper if it contains one or more local() functions but not url(). 
  5. The less particular font versions should be listed after the more specific font variants. 
  6. By enabling the user to specify their unique fonts, @font-face enables users to move beyond web-safe fonts and eliminate the need for an internet connection.

How to apply CSS @font-face 

For fonts hosted on one's servers, "@font-face" is a great option since it enables developers to show a font on a website even in cases when the user does not have the font installed on their machine. The rule tells the browser to get the font file from its host location and then present it in the CSS-specified format. Instead of being limited to using web-safe fonts that consumers have preinstalled on their computers, this enables designers to utilize a wider range of fonts.

Syntax:

The @font-face rule has a simple structure at its core. Since it appears at the start of a stylesheet, the fonts will load first. 

The font-family, src, font-strength, font-weight, and font-style factors make up the font-face rule. Below is a discussion of these descriptions' roles.

@font-face {

  font-family: fontName;

  src: url(fontFile path);

  font-stretch: font-stretch Property;

  font-weight: font-weight Property;

  font-style: font-style Property;

}

Parameters

Four parameters can be used with the @font-face rule, as explained below: 

font-family: This property indicates an element's font. This is a necessary description.

src: This retains the file path (URL) and is used to define the location (URL) of the external resource. Its value is a list of locally installed font face names or external references ordered by comma. The user agent cycles through the list of references whenever a typeface is required, selecting the first one it can activate. The user agent loads the next font in the list and ignores fonts with incorrect data or local font faces that cannot be located.

font-stretch: Use font-stretch to adjust the text's width and height. 

font-weight: This property is used to specify the font's weight or thickness when used with HTML text. 

font-style: The value defined by the font-style descriptor will be utilized to match styles to certain faces.

Possible values:

  1. normal
  2. italic
  3. oblique

The default value is normal.

Note: There is 5 Font format those are: TTF/OTF, WOFF, WOFF2, SVG, and EOT.

Example 1: This example shows how to declare the various font characteristics to decorate the text according to the @font-face rule. 

<html>

<head> 

<style>

   @font-face {

      font-family: "Calibri Font";

      src: url("font/Calibri.woff");

   }

   body {

      font-family: "Calibri Font", Calibri;

   }

</style>

</head>

<body>

   <h2>@font-face at-rule</h2>

   <p>This is called as Calibri Font.</p>

</body>

</html>

Output

Font-Face in CSS

Example 2: By indicating the file path's source and format, this example demonstrates how to utilize the @font-face rule.

<html lang="en">

<head>

<title>Example for CSS @font-face rule</title>

<style type="text/css">

@font-face {

font-family: "Italic";

src: url("/examples/fonts/TimesNewRoman-Regular.eot");

src: url("/examples/fonts/TimesNewRoman-Regular.ttf") format("truetype");

font-stretch: normal;

font-weight: normal;

font-style: normal;

}

@font-face {

font-family: "TimesNewRomanBold";

src: url("/examples/fonts/TimesNewRoman-Bold.eot");

src: url("/examples/fonts/TimesNewRoman-Bold.ttf");

font-stretch: normal;

font-weight: normal;

font-style: normal;

}

/* Specifying the TimesNewRoman bold font */

h1 {

font-family: "TimesNewRomanBold", Arial, Times New Roman-serif;

color: blue;

}

p {

font-family: "Times New Roman", Arial, Times New Roman-serif;

}

</style>

</head>

<body>

<center>

<h1>Welcome</h1>

<p>Let's start now</p>

</center>

</body>

</html>

Output

Font-Face in CSS

Impact on outcomes 

A boring website looks better with web fonts. Performance issues arise because the custom fonts must be downloaded before they can be shown. 

Before the downloaded fonts could be utilized, the fallback fonts were first loaded. 

But until the special font loads by default, the browsers conceal the content.