Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To use local font in HTML using font face

Tags:

I trying to use local font to apply styles in html, below is the code.Font is not getting applied for harlow class used element

<!DOCTYPE html> <html> <head> <style> @font-face {     font-family: myFirstFont;     src:local("C:\Users\Website\fonts\Harlow_Solid_Italic.ttf"); }  .harlow{     font-family: myFirstFont; } </style> </head> <body> <div>With CSS3, websites can finally use fonts other than the pre selected "web-safe" fonts.</div> <p><b class="harlow">Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule with the WOFF format (only support for EOT format).</p> </body> </html> 
like image 477
anavaras lamurep Avatar asked Jun 28 '16 20:06

anavaras lamurep


People also ask

How do I use face fonts in HTML?

You can use a <basefont> tag to set all of your text to the same size, face, and color. The font tag is having three attributes called size, color, and face to customize your fonts. To change any of the font attributes at any time within your webpage, simply use the <font> tag.

What is the use of font face?

The @font-face CSS at-rule specifies a custom font with which to display text; the font can be loaded from either a remote server or a locally-installed font on the user's own computer.


2 Answers

I made the following changes and I got the result

  • Quotation marks for font-family
  • Using of URL instead of local
  • Changing of "\" to "/"

Note: Use of the local css function throws an error in the developer console saying resource is not loaded. See the modified code below.

<!DOCTYPE html>  <html>  <head>  <style>  @font-face {      font-family: "myFirstFont";      src: url("C:/Users/Desktop/Website/fonts/Harlow_Solid_Italic.ttf");  }    .harlow {      font-family: "myFirstFont";  }  </style>  </head>  <body>  <div>With CSS3, websites can finally use fonts other than the pre selected "web-safe" fonts.</div>  <p><b class="harlow">Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule with the WOFF format (only support for EOT format).</p>  </body>  </html>
like image 186
anavaras lamurep Avatar answered Sep 28 '22 12:09

anavaras lamurep


Use the correct path for file. your path does not work on the host. because your host has no drive 'c:/...' or anythings like this. so you can use

<!DOCTYPE html> <html> <head> <style> @font-face {     font-family: myFirstFont;     src:url("/fonts/Harlow_Solid_Italic.ttf"); }  .harlow{     font-family: myFirstFont; } </style> </head> <body> <div>With CSS3, websites can finally use fonts other than the pre selected "web-safe" fonts.</div> <p><b class="harlow">Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule with the WOFF format (only support for EOT format).</p> </body> </html> 
like image 42
MN. Vala Avatar answered Sep 28 '22 10:09

MN. Vala