Open In App

How to include a font .ttf using CSS ?

In this article, we are going to learn how to include a font .ttf using CSS. In the late 1980s, after getting beaten by Adobe’s type 1 font, Apple came up with a new font format type which is .ttf(True Type Font). These fonts were so awesome that, they became the most common font formats all over the world in a very short time. In fact, windows itself started using them in their operating system.

Steps to include font .ttf using CSS:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>This font is awesome</h2>
</body>
</html>
@font-face {
font-family: myFirstFont;
src: url(ArianaVioleta-dz2K.ttf);
}

h2 {
font-family: myFirstFont;
color: darkgreen;
}

font in browser

Example: In this example, we are trying different font.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
</head>
 
<body>
    <p>The font on this paragraph looks awesome</p>
</body>
 
</html>




@font-face {
   font-family: myFirstFont;
   src: url(ChrustyRock-ORLA.ttf);
}
  
h2 {
   font-family: myFirstFont;
   color: darkgreen;
}

  Output: 

example with a new font

Supported Browser:




Article Tags :