How to use custom font in website - html

I use this code in style.css file and can add my custom font where I want.
#font-face {
font-family: Titr;
src: url('fonts/L4i_Titr.ttf');
url('Thonburi-Bold.eot');
}
But this work for localhost. When I put my local website in the web, font don't work.
What's problem?
What's the solution?

Make Sure fonts are uploaded on server and in your question path is wrong for .eot format. Since All latest browser support the .woff font format type. So you can use .ttf and .woff font format type.
Thats work on your local machine because of fonts are available on your system. After uploading the font on server and given a correct file path in CSS file your custom fonts will appear.
As well make sure you define the font MIME Type for all fonts type you are using. For example .woff format set a MIME type in server like application/x-font-woff .
Using #font-face Generator you can convert font format from .ttf to .eot, .svg, .woff.
Update:
On .htaccess file add font the following types:
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
CSS
#font-face {
font-family: 'Titr';
src: url('fonts/L4i_Titr.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
url('fonts/L4i_Titr.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */
}

If Kheema Pandey's solution dosen't work then maybe there is something wrong with the font file. And if this is true then the only reson because of which the font is working on localhost is because you already have it installed on your system. So just check the font file for any errors.
EDIT :
Have you tried opening the online page in multiple browsers. If not then try it beacuse it might be possible that a specific browser might not support a font(happened with me).

Related

#font-face not working on chrome but works on other browsers

I want one simple thing...my font to work on chrome.
#font-face{
font-family: "Iosevka";
src: url("http://www.some_url/iosevka-regular.woff2") format(woff2),
url('http://www.some_url/iosevka-regular.otf') format(opentype),
url('http://www.some_url/iosevka-regular.ttf') format(truetype);
url('http://www.some_url/iosevka-regular.eot) format(embedded-opentype);
}
This works on safari and firefox but not chrome. I am not exactly sure why
I have looked at several posts saying I need to add more font support so I have ttf, woff2, eot, and otf but this still doesn't work.
Does anyone know what is going on?
Simplest supported loading of a font on the web today. Only need one font file and it needs to be used.
Two CSS rules and a HTML tag.
Microsoft was the holdout for TTF although they were part of building the TTF. All systems have the license to use TTF and caniuse reports all browsers supporting it.
Note this does not mean you can use anybodies licenced font. It means you can use TTF to display the font.
OTF is open license so no license is required and supported by all systems including Microsoft edge.
Not sure of the status of Woff and SVG is not supported by Chrome.
#font-face {
font-family: "Logo";
src: url("/fonts/logo.ttf"); /* or url("/fonts/logo.otf") */
}
.logo {
font-family: Logo;
font-size: 80px;
font-weight: normal;
}
<h1 class="logo">
Browsers don't download the font until they need to use the font. But the font can be downloaded with Javascript if one does not like the normal behavior.

Woff2 #font-face Won't Load Properly

I am having trouble trying to import a woff2 font file for use in a simple test webpage.
Below is how I have organized and coded the test webpage:
Added .woff file
Everything is in one folder named 'test' and the #font-face src references the local .woff2 font file I want to test. Unfortunately, the font for the heading does not show the proper font unless I use the .ttf font file.
This is how it looks when I use the .ttf file:
and this is how it looks when I use the .woff2 file:
I feel as though I am making a simple formatting mistake somewhere, but I can't seem to figure out where I'm going wrong. Any help is appreciated.
I finally found out why the font wouldn't work! I had downloaded the Latin-Extended version of the font, which wouldn't display correctly. All I had to do was download the plain Latin version of the font and it worked as it should.
I thought to download the plain Latin version of the font after taking a look at this post by limonte: Font rendering in Chrome (woff2) - after load font family doesn't want to change.
.woff2
First Way - Steps:
Go to iis server and then "Sites"
Double click on website you want to add MIME type.
Right pan find and click on "MIME Types"
In right most pan, click on "Add"
Type in ".woff2" in "File name extensions:" and "application/font-woff2" in "MIME Type:"
Done. Refresh your website page, this should reflect now.
Second Way - Steps:
Add Below into the web.config.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
Note: If already there then just add entry for woff2. Else add entire tag.
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
hope this can help found it a while back when doing something similar(not taking credit for this as found it not wrote it)
I would however suggest trying woff instead of woff2 depending on your browser..

Internet Explorer 10 on Windows 7 does not load embedded fonts

Problem details:
I have the problem that Internet Explorer 10 (under Windows 7 - 64 Bit) does not load fonts embedded with #font-face in CSS. Instead it shows "Arial" or a font like that. I have tested this problem on multiple devices:
Windows 8 with Internet Explorer 11 (64 Bit)
Windows 8 with Internet Explorer 10 (64 Bit)
Windows 7 with Internet Explorer 10 (64 Bit)
But for me this problem never occured. But the strange thing is that this problem occurs on a customer PC with Internet Explorer 10 and Windows 7 64 Bit.
The other strange thing is that in the "Network" tab of Internet Explorer shows all resources, but IE will not show any font.
Luckily I have a customer PC to debug this issue. I could not figure out what the problem is yet.
What I already did to find a solution:
I have ensured that the path and font-family name is correct. I also ensured that the #font-face command is inside the CSS file I have embedded
I tried to add the doctype from:
<!DOCTYPE html> to
<!DOCTYPE html SYSTEM "about:legacy-compat">
I updated the meta tags, e.g.:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
I also tried to change the order of the font-face url commands
I removed the ' from the name of the font-family, so from:
font-family: 'My font'; to
font-family: My font;
I also tried to force the correct MIME of the font with a .htaccess file like:
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-opentype .otf
AddType image/svg+xml .svg
AddType application/x-font-ttf .ttf
AddType application/x-woff .woff
I also installed the website on another server to be sure this is not a server problem
I ensured that the chekboxes in Internet Explorer 10 under "Internet options" -> "Accessibility" are not checked
Technical things:
I am embedding my CSS with:
<link rel="stylesheet" type="text/css" href="assets/css/base.css">
My #font-face command looks like:
#font-face {
font-family: MyFont;
src: url('myPath/MyFont.eot');
src: url('myPath/MyFont.eot?#iefix') format('embedded-opentype'),
url('myPath/MyFont.woff') format('woff'),
url('myPath/MyFont.ttf') format('truetype'),
url('myPath/MyFont.svg#myfont') format('svg');
font-style: normal;
font-weight : normal;
}
// EDIT:
I just want to point out that CSS fonts work generally. But unfortunately not in on this site.
Getting #font-face working in Internet Explorer may just be spooky enough.
as well as you know #font-face already works in Safari 3 via WebKit and is supported in the latest Firefox 3.1 beta.
With IE, that means around 75% of the world audience could see custom typefaces today if their EULAs allowed it.
Fortunately, there are good free faces available to us already, as well as some commercial faces that permit embedding.
so..my onion to use latest version of browser like- chrome, firefox 3.1, safari 3.
Thank you.....
Here is what solved my problem:
I found out that the customer has a "whitelist" of hosts. Unfortunately my server wasn't on this list. So the customers proxy blocked all font requests from my server.
I don't know the reason for it, but I think the one who configured the proxy thought that a virus or trojan could be downloaded over a font.

Why not use otf format in fontawesome to fix chrome bad rendering issue?

Trying to find a way to get better antialiased rendering of fontawesome icons in chrome in windows i found that using 'otf' format solve the problem.
i used in fontawesome.css:
src: url('../font/fontawesome.otf?v=3.1.0') format('opentype'),
url('../font/fontawesome-webfont.eot?#iefix&v=3.1.0') format('embedded-opentype'),
url('../font/fontawesome-webfont.woff?v=3.1.0') format('woff'),
url('../font/fontawesome-webfont.ttf?v=3.1.0') format('truetype'),
url('../font/fontawesome-webfont.svg#fontawesomeregular?v=3.1.0') format('svg');
rendering is very good in chrome with a minor issue "in some icons the very top of the icon is cropped", other browsers render the icons clearly without any issue.
my question, why otf version is not used in fontawesome to fix chrome bad rendering issue, the otf file is already present but not included in css?
Have you tried this?
I have a problem with icons getting cut off at the top but loading the otf file doesn't fix it.
As chrome can also load svg fonts then the opentype will be downloaded and then overridden with an extra http request for the svg.
So it seems like you are downloading extra data and ending up with the same result?

#fontface not working for IE9

I'm having a font-face the menu of my webpage. For all browsers is loading fine except for Internet Explorer. Here's what I'm using in my css:
#font-face{
font-family: 'MyriadProSemibold';
src: url('fonts/MyriadPro-Semibold.eot');
src: local(MyriadPro-Semibold), url('fonts/MyriadPro-Semibold.otf') format('opentype');
}
Fonts are in a folder called fonts that is located in the same folder as the css file. I don't know how to debug this problem is anyone could point out what need to be done in order to make them work for IE9?
I suggest you put the opentype file into the font-face generator. Click on generate and download the .zip file you get.
Copy the fonts to your webhost and copy the CSS styles in the stylesheets.css into your stylesheet, you can change the name and you need to correct the paths to the new paths. Now it works on FireFox 3.5+, Chrome4+, Opera10+, iPad, iPhone, IE4+ (!) and Safari3.1+.
This is the font-face format I use:
#font-face {font-family: 'MyriadProSemibold';
src: url('MyriadProSemibold.eot');src: url('MyriadProSemibold.eot?#iefix') format('embedded-opentype'),url('MyriadProSemibold.woff') format('woff'),url('MyriadProSemibold.ttf') format('truetype');}