As a small optimisation technique I want to serve the 'Avenir Next - Regular' font locally via css (so if a user has this font locally it will use it rather than download a woff2/woff/etc).
This font, for example, has been in IOS since version 6 so it's a quick win.
However I am not sure how to specify the local font name in the css stack? Do I need the word regular? Is there a program that would help?
#font-face {
font-family: 'Avenir';
src: local("Avenir Next Regular"), /* THIS? */
local("Avenir-Next-Regular"), /* THIS? */
local("Avenir-Next"), /* SOMETHING ELSE? */
url('/fonts/AvenirNextLTW04Regular.woff2') format('woff2'),
url('/fonts/AvenirNextLTW04Regular.woff') format('woff'),
url('/fonts/AvenirNextLTW04Regular.ttf') format('truetype');
}
Do I need to specify a font weight to get the 'regular' version? And then is there a way in devtools to see if it works? I presume not seeing a call to an external font file means success?
You should use the correct font name as defined in the font file. If you are on Windows you can install Microsoft's Font properties extension. When installed, you just right click the font file and select Properties. There you will find extra tabs with the font's info. One of them will show the fonts name.
I guess it will be like this:
#font-face {
font-family: 'Avenir Next - Regular';
src: local('Avenir Next'),
url('/fonts/AvenirNextLTW04Regular.woff2') format('woff2'),
url('/fonts/AvenirNextLTW04Regular.woff') format('woff'),
url('/fonts/AvenirNextLTW04Regular.ttf') format('truetype');
}
The font family reflects the base name of a font, while the variants are the children (font faces) and are defined by weight (e.g. Regular, Bold) and style (normal & italic).
When defining custom #font-faces, make sure to define a common font-family, so that font-weight and font-style gets applied properly and the font-face switches accordingly within the same font family.
There is no official naming convention for the various font faces themselves, but most fonts do follow this this pattern:
[Font Name] [Weight?] [Italic?]
The names for the common weights are usually Thin, ExtraLight, Light, Regular, Medium, SemiBold, Bold, ExtraBold and Black.
However, some fonts may introduce an extra space in the Extra-variants or substitute Semi with Demi. More about the possible names can be found here.
Minor common exception: For the default 400-weight font, the name usually is Font Name Regular, while the weight is left out of the italic variant: Font Name Italic
Here is a table of possible font names for the imaginary font family Cool Font:
Weight
Style
Likely name
100
normal
Cool Font Thin
200
normal
Cool Font ExtraLight
300
normal
Cool Font Light
400
normal
Cool Font Regular
500
normal
Cool Font Medium
600
normal
Cool Font SemiBold
700
normal
Cool Font Bold
800
normal
Cool Font ExtraBold
900
normal
Cool Font Black
100
italic
Cool Font Thin Italic
200
italic
Cool Font ExtraLight Italic
300
italic
Cool Font Light Italic
400
italic
Cool Font Italic
500
italic
Cool Font Medium Italic
600
italic
Cool Font SemiBold Italic
700
italic
Cool Font Bold Italic
800
italic
Cool Font ExtraBold Italic
900
italic
Cool Font Black Italic
Keep in mind, that your font family might diverge from this table, so it is always best to check the font itself.
Example:
Assuming the entire family of Cool Font consists of an (italic) Regular and Bold font face sharing the naming convention described above, the correct definition could be:
#font-face {
font-family: 'Cool Font';
src: local('Cool Font Regular'),
url('Cool_Font_Regular.woff2') format('woff2'),
url('Cool_Font_Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
}
#font-face {
font-family: 'Cool Font';
src: local('Cool Font Bold'),
url('Cool_Font_Bold.woff2') format('woff2'),
url('Cool_Font_Bold.woff') format('woff');
font-weight: 700;
font-style: normal;
}
#font-face {
font-family: 'Cool Font';
src: local('Cool Font Italic'),
url('Cool_Font_Italic.woff2') format('woff2'),
url('Cool_Font_Italic.woff') format('woff');
font-weight: 400;
font-style: italic;
}
#font-face {
font-family: 'Cool Font';
src: local('Cool Font Bold Italic'),
url('Cool_Font_Bold_Italic.woff2') format('woff2'),
url('Cool_Font_Bold_Italic.woff') format('woff');
font-weight: 700;
font-style: italic;
}
If you don't know the correct variant name of a font, you can always define multiple local variants without any downsides:
#font-face {
font-family: 'Cool Font';
src: local('Cool Font SemiBold'),
local('Cool Font Semi Bold'),
local('Cool Font DemiBold'),
local('Cool Font Demi Bold'),
url('Cool_Font_SemiBold.woff2') format('woff2'),
url('Cool_Font_SemiBold.woff') format('woff');
font-weight: 600;
font-style: normal;
}
When you don't want to let the user download a font and let it use the 'Avenir Next - Regular' font, you should put this font first in line in the font-declaration. Look into your own fonts for the exact name and set (only):
font-family: "Avenir Next - Regular", Arial, Helvetica, "sans-serif";
But check if 'Avenir Next - Regular' is so widely local available (not likely, because it is an expensive font).
Related
As far as i am aware if you use the option "swap" for the property "font-display", Apple Mac uses Helvetica as fallback font and Windows Arial. Is it possible to define my own web-safe font like "Tahoma"?
Example code:
#font-face {
font-family: 'MyFancyFont';
src: local('MyFancyFont'), url(/fonts/MyFancyFont/MyFancyFont.woff2) format('woff2');
font-display: swap;
UseMyCustomFallbackFont: Tahoma
}
I believe this is done in the font-family definition, not the #font-face itself.
ex.
.my-text{
font-family: MyFancyFont, Tahoma;
}
This will show Tahoma until MyFancyFont is loaded.
You can get even more specific control if you use something like Webfont loader.
https://github.com/typekit/webfontloader
I have three files for a font, the normal one, the bold one and the light one.
How can I set the light one on font-face, since font-weight:light does not exist?
By the way, is font-weight:lighter relative to something? If yes, to what?
Try these (one at a time):
font-weight: lighter;
font-weight: 100;
font-weight: 200;
font-weight: 300;
You need to get font that supports font-weight of different sizes, you should be able to specify the font weight as a number, for example:
font-weight:300 - should be light
font-weight:400 - should be normal
font-weight:700 - should be bold
But it will depend on how you are defining them in your font-face declaration, you should put the font weights in there, for example here is one for HelveticaNeue-Light
#font-face{
font-family:"HelveticaNeue";
src: url("/fonts/fontfile.eot");
src: local('Helvetica Neue Light'), local('HelveticaNeue-Light'),
url("/fonts/fontfile.eot?#iefix") format("embedded-opentype"),
url("/fonts/fontfile.woff") format("woff"),
url("/fonts/fontfile.ttf") format("truetype"),
url("/fonts/fontfile.svg") format("svg");
font-weight: 300;
font-style: normal;
font-stretch: normal;
}
Then you can use:
p {
font-family:"HelveticaNeue";
font-weight:300;
}
And it will use that font-face definition, you can define multiple of these with different font-weights that match up to various files of different weights should you need to.
You can get font files that have multiple weights embedded into one file but most of the time now I believe the come in separately!
I'm adding multiple weights and styles of a single font to a font-face in a Rails project. I know that order matters here, ie. first define normal, then bold, then italic, then italic bold.
However, when I try to define normal first and then italic second, what shows up on my site by default is the italic version.
fonts.scss contains:
#font-face {
font-family: 'Sentinel Book';
src: font-url('sentinel-book-webfont.eot');
src: font-url('sentinel-book-webfont.eot?#iefix') format('embedded-opentype'),
font-url('sentinel-book-webfont.woff2') format('woff2'),
font-url('sentinel-book-webfont.woff') format('woff'),
font-url('sentinel-book-webfont.ttf') format('truetype'),
font-url('sentinel-book-webfont.svg#sentinelbook') format('svg');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'Sentinel Book';
src: font-url('sentinel-bookital-webfont.eot');
src: font-url('sentinel-bookital-webfont.eot?#iefix') format('embedded-opentype'),
font-url('sentinel-bookital-webfont.woff2') format('woff2'),
font-url('sentinel-bookital-webfont.woff') format('woff'),
font-url('sentinel-bookital-webfont.ttf') format('truetype'),
font-url('sentinel-bookital-webfont.svg#sentinelbook_italic') format('svg');
font-style: italic, oblique;
}
$font-family-serif: 'Sentinel Book', sans-serif;
$font-family-base: $font-family-serif;
Note that I'm using Bootstrap + SASS and overriding their variables, but still the default I'm seeing is italic:
If I rearrange the order in which the styles are defined (italic first, then norma), my text appears normal. But if I italicize anything (using <em> tags for example), the browser does its own italicization instead of using the italic version of the webfont loaded.
Any tips here would be appreciated!
The reason is that the declaration font-style: italic, oblique is syntactically malformed (see CSS 3 Fonts on font-style; only one keyword is allowed as the value). Change it to
font-style: italic;
It may sound surprising that the error in declaring the italic typeface causes all text to be rendered in italic. But the reason is that by CSS error handling rules, the incorrect declaration is ignored, so in this #font-face rule, font-style is defaulted to normal. This means that it will be applied to normal text; but the font file contains the italic typeface.
When you changed the order of the font-face rules, the latter rule that refers to the regular typeface will be used for normal text. Since there is no rule italic text, browsers will render italic text using regular typeface, applying algorithmic slantic (“faux italic”, “synthetic italic”) to it (usually; this in principle depends on browser).
The keywords italic and oblique mean the same thing in practice, though in theory they could have different meanings. But using them both in a font-style value makes the declaration syntactically invalid.
Does anyone know how to use the Font Squirrel #font-face kit generator, or something similar, to output a variant of a font, i.e. the bold variant?
I am using Gill Sans on my website and it is set to "font-weight: 900" or "font-weight: bold," which looks great on my machine because it has the font installed. But if I just embed the font generated by Font Squirrel, I only get the "regular" variant and "bold" doesn't display correctly.
Does anyone know of a way to embed the bold variant of a font?
There is only one file for Gill Sans, and when I upload it, here is what Font Squirrel gave me:
#font-face {
font-family: 'GillSansRegular';
src: url('../fonts/gillsans-webfont.eot');
src: local('☺'), url('../fonts/gillsans-webfont.woff') format('woff'), url('../fonts/gillsans-webfont.ttf') format('truetype'), url('../fonts/gillsans-webfont.svg#webfontDATch26L') format('svg');
}
The original file no doubt contains the information for bold, italic, etc., but I'm wondering if Font Squirrel strips out the variants, leaving me with only the "regular" variant.
Even if I just add bold to everything it doesn't show up bold anywhere:
#font-face {
font-family: 'GillSansBold';
src: url('../fonts/gillsans-webfont.eot');
src: local('☺'), url('../fonts/gillsans-webfont.woff') format('woff'), url('../fonts/gillsans-webfont.ttf') format('truetype'), url('../fonts/gillsans-webfont.svg#webfontDATch26L') format('svg');
font-weight: bold;
}
Nothing is bold even when I strip all font-familys and font-weights from anywhere else in my stylesheets. Everything just shows up as Gill Sans Regular.
I just received an email from Font Squirrel: the generator doesn't split .dfont files in the current version, so that explains it.
When we define #font-face styles, we can define whether the referenced files are for the bold, italic, or bold italic versions of a font, as discussed in this SO question:
How to add multiple font files for the same font?
Example:
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}
However, Font Squirrel doesn't generate #font-face kits this way. They do something like this instead:
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'FontinSansBold';
src: local('☺'), url('fontin_sans_bold.woff') format('woff');
font-weight: normal;
font-style: normal;
}
Which means in our CSS files we have to do things like this:
h2 {
font-family: 'FontinSansBold', Verdana, sans-serif;
font-weight: normal;
}
Why doesn't Font Squirrel use the font-weight and font-style declarations to distinguish the bold and italic variants? Why use a separate font family? Do they know something about (lack of) support for this feature in some browser?
By default, Font-Squirrel does this in order to increase support with user-agents that do not follow specification (those that ignore font-weight and font-style).
If you do not care about those outdated user-agents, you may enable the "Style Linking" option which is available in the expert section of the #font-face kit generator. Note that IE8 and below ignores numbered font-weight values and only support normal and bold (and corresponding 400, 700 weight values).
It does involve poking around inside the font to determine when a font is bold or italic. And certain bits must be set inside the font in order for IE to pick up the style linking. Most bold / italic fonts have these bits set, but not all. We are working on a way to make this more automatic.
It seems Internet Explorer 8 may be one of those "older" user agents that doesn't support font-weight and font-style
I am trying to make bold/italic/bolditalic automatic using the #font-face and font-family.
My attempts so far have yielded nothing. Here is a page demonstrating the problem.
http://clearimageonline.com/apps/playground/fonts/test_IE.html
Anyone here encountered this and have a solution that works with IE8?
I have searched and fiddled most of this week for an answer to this. It appears that IE8 wont let me do this.
Here is a proposed workaround (very ugly workaround)....
http://clearimageonline.com/apps/playground/fonts/proposed_IE.html
These test pages are designed for Internet Explorer ONLY. This test is limited to IE. Cross Browser functionality will obviouosly be a part of a final solution.
The problem using the default FontSquirrel's approach is that if the fallback font loads, all weights will be lost because they are all set to normal. I think the style linking is the best approach.
If you are worried about IE8 users you can use a conditional css.