Google font not working - css

I want to use Lato light google font on my website.
Added link herf=... and font family tag per instruction, but it's not working properly.
On my laptop where I have Lato fonts installed, I see Lato light font implemented; however, on my friend's computer as well as on my phone, I'm not seeing Lato light font (I see some random font instead)
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
body {
font-family: 'Lato', sans-serif;
background-color: white;
font-weight: 300;
color: #595959;
letter-spacing: 1.4px;
}
I don't know what the problem is -- when I delete font-family: 'Lato', sans-serif; below body {, I no longer see Lato font on my computer.... so it's working, but quite properly.
Input would be greatly appreciated!!!

Try to this way, I think this is working very well
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">

It's working fine with right html declarations. And you can use updated lato font link
body {
font-family: 'Lato', sans-serif;
background-color: white;
font-weight: 300;
color: #595959;
letter-spacing: 1.4px;
}
<!Doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
</head>
<body>
<p>I am paragraph</p>
</body>
</html>

Related

#font-face not working in html email

I am trying to use a custom font in a newsletter/html email. I got the #font-face import working in safari, firefox and chrome, but as soon as I try to use it in an email client (tested with apple mail, thunderbird and gmail) the custom font is not displayed. I read several posts on SO about this but the suggested solution is always to check if the mail-client is supported (which it is) and to use different formats(which I do). It is not working with google fonts either. So are there any other suggestions what could be wrong?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="x-apple-disable-message-reformatting">
<!--[if !mso]><!-->
<style type="text/css">
#font-face {
font-family: 'myfont';
src: url('https://example.com/various/myfont-Regular.eot');
src: url('https://example.com/various/myfont-Regular.woff2') format('woff2'),
url('https://example.com/various/myfont-Regular.woff') format('woff'),
url('https://example.com/various/myfont-Regular.ttf') format('truetype'),
url('https://example.com/various/myfont-Regular.svg#FreelandforDouglas-Regular') format('svg'),
url('https://example.com/various/myfont-Regular.eot?#iefix') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}
</style>
<!--<![endif]-->
</head>
As you mention, #font-face is not supported in some email clients. Depending on what fonts you're designing with, you could specify a font-stack the starts with a custom font and falls back to similar system fonts.
This code I use for web fonts goes something like this:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="x-apple-disable-message-reformatting">
<!-- Desktop Outlook chokes on web font references and defaults to Times New Roman, so we force a safe fallback font. -->
<!--[if mso]>
<style>
* {
font-family: sans-serif !important;
}
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet'>
<!--<![endif]-->
There are a few ways to reference web fonts in email, I prefer using the <link> method.
Alternatively you can run your font through Font Squirrel's Font Generator and use the #import method:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="x-apple-disable-message-reformatting">
<!-- Desktop Outlook chokes on web font references and defaults to Times New Roman, so we force a safe fallback font. -->
<!--[if mso]>
<style>
* {
font-family: sans-serif !important;
}
</style>
<![endif]-->
<!--[if !mso]><!-->
<style>
#font-face {
font-family: 'MyWebFont';
src: url('http://www.website.com/webfont.eot');
src: url('http://www.website.com/webfont.eot?#iefix') format('embedded-opentype'),
url('http://www.website.com/webfont.woff2') format('woff2'),
url('http://www.website.com/webfont.woff') format('woff'),
url('http://www.website.com/webfont.ttf') format('truetype'),
url('http://www.website.com/webfont.svg#svgFontName') format('svg');
}
</style>
<!--<![endif]-->
You might not need all of these font formats (eg. you probably don't need the SVG format), I'd recommend testing.

How to use different kind of Google Font types?

I want to use a Google Font with different types (Light, Black, Semi-bold).
This is the link for the Google Font: https://fonts.googleapis.com/css?family=Exo+2:300,400,600,900
The regular is working fine, font-family: 'Exo 2'; But I was wondering how I can use the Light, Black ones. I've tried Exo 2 Black/Light but that didn't seem to work.
I've also read the documentation, but that didn't have the answer also.
You first have to load you font in the document's head and than use the font in conjunction with the right font-weight in your CSS.
PS: You got a little typo in your font URL.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Website</title>
<link href="https://fonts.googleapis.com/css?family=Exo+2:300,400,600,900" rel="stylesheet">
<link href="path/to/styles.css" rel="stylesheet">
</head>
<body>
…
</body>
</html>
styles.css
.light {
font-family: 'Exo 2';
font-weight: 300;
}
.normal {
font-family: 'Exo 2';
font-weight: 400;
}
.semi-bold {
font-family: 'Exo 2';
font-weight: 600;
}
.black {
font-family: 'Exo 2';
font-weight: 900;
}
You need to use the font-weight property in your css with the correct numeric representation of the font-weights.
In your case, you can see in the URL the different weights available:
https://fonts.googleapis.com/css?family=Exo+2:300,400,600,900
The 300,400,600,900 correspond to font weights.
300 - Light
400 - Regular (so no need to declare it)
600 - Bold
900 - Black
in your case font-weight: 300 would be light and font-weight: 900 would be black.

IE 11 not displaying font weights correctly from Google Fonts

IE 11 is not displaying my specified font weights correctly from Google Fonts. I can not get the problem to replicate in JSFiddle
When using Google Fonts the font weight is displayed correctly if I only specify one weight i.e. if I import the fonts with the following link the light version is brought in.
<link href="https://fonts.googleapis.com/css?family=Oswald:300" rel="stylesheet">
If change the link like so:
<link href="https://fonts.googleapis.com/css?family=Oswald:400" rel="stylesheet">
The regular weight is brought in.
However if I try to import both weights IE 11 only shows the heavier font despite me specifying font weight in the CSS. Chrome shows the light version as it should.
Link:
<link href="https://fonts.googleapis.com/css?family=Oswald:300,400" rel="stylesheet">
CSS:
.light {
font-family: 'Oswald', sans-serif;
font-weight: 300;
font-size: 16px;
}
.regular {
font-family: 'Oswald', sans-serif;
font-weight: 400;
font-size: 16px;
}
HTML:
<p class="light">This Is A Test Of Google Fonts Displayed in IE 11</p>
<p class="regular">This Is A Test Of Google Fonts Displayed in IE 11</p>
Chrome Screenshot:
IE Screenshot:
Full Local HTML for Test case:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Font Test Page</title>
<link href="https://fonts.googleapis.com/css?family=Oswald:300,400" rel="stylesheet">
<style>
.light {
font-family: 'Oswald', sans-serif;
font-weight: 300;
font-size: 16px;
}
.regular {
font-family: 'Oswald', sans-serif;
font-weight: 400;
font-size: 16px;
}
</style>
</head>
<body>
<p class="light">This Is A Test Of Google Fonts Displayed in IE 11
</p>
<p class="regular">This Is A Test Of Google Fonts Displayed in IE 11
</p>
</body>
</html>
According to Can I Use... Internet explorer 6-11 doesn't support the font-weight:<number> syntax:
(source: https://caniuse.com/#feat=mdn-css_properties_font-weight_number )
A solution for that browser would be to have differently named font definitions for all the needed weights.

IE7 displays trademark entity as serif within sans-serif font

I have a webpage that uses Google's Open Sans font. The webpage also uses an HTML entity for the trademark symbol (™).
In Internet Explorer 7, this entity is not displayed using Open Sans, it is displayed in a serif font:
Here is a short page that reproduces the problem:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:400,700" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:400" />
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:700" />
<![endif]-->
<style type="text/css">
* {
font-family: "Open Sans", Arial, sans-serif;
}
</style>
</head>
<body>
<h1>This is trademarked™</h1>
<p>This is trademarked™</p>
</body>
</html>
Using the entity ™ results in the same problem, as does using a literal ™, but oddly enough the ® entity displays correctly.
Is there anyway to get this entity to render either in Open Sans, or if that fails, in a sans-serif font?
Both Open Sans & Arial don't have entities, so your browser will default to a system font for them. Try adding some alternative system fonts in your lineup:
font-family: "Open Sans", "Helvetica Neue", Helvetica, Calibri, Arial Unicode MS, Lucida Sans Unicode, DejaVu Sans, FreeSans, sans-serif;

google font only ie9 and the rest?

I am using Google Fonts to load two fonts. Since they look absolutely horrible in anything below ie9 I want to disregard them. Here is what I am thinking :
<!DOCTYPE html>
<!--[if lte IE 8 ]> <html class="ie8" lang="en-US"> <![endif]-->
<!--[if !IE]><!--><html lang="en-US"><!--<![endif]-->
then in my css I could use something like this :
h1{
font: normal 33px/50px 'Open Sans', 'Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif;
}
.ie8 h1{
font: normal 33px/50px 'Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif;
}
That takes care of it trying to use Open Sans. What about loading the actual stylesheet. Would something like this be fine?
<!--[if !(lte IE 8) ]>
<link href="http://fonts.googleapis.com/css?family=Kite+One|Open+Sans:400italic,400,700" rel="stylesheet" type="text/css">
<![endif]-->
This would prevent ie8 and under from even loading the css and prevent wasted download - correct? Is this the correct syntax?
Anyone recommend a better way? I have tried loading all the fonts separate and they still do not work right in ie8 and 7 so that is not an option.
You'd have to use something like this to exclude IE8 and lower:
<!--[if gt IE 8]>
<link href="http://fonts.googleapis.com/css?family=Kite+One|Open+Sans:400italic,400,700" rel="stylesheet" type="text/css">
<![endif]-->
<!--[if !IE]> -->
<link href="http://fonts.googleapis.com/css?family=Kite+One|Open+Sans:400italic,400,700" rel="stylesheet" type="text/css">
<!-- <![endif]-->
The first one only loads the font for IE9 and above. The second one loads it for all non-IE browsers.
Alternatively, you could load the fonts with JavaScript.

Resources