CSS weights are not a formal, real thing in font land, they're just a convention that only CSS uses, and has no effect on weights indicated by fonts as part of a font family. Those values are the usWeightClass
in the OS/2
table of OpenType fonts, and can be any number between 0 and 65355, with the numbers being purely based on what the designers/foundry means them to have.
So, looking at the Lato fonts, we see the following weights:
- Regular: OS/2.usWeightClass = 400
- Light: OS/2.usWeightClass = 300
- Thin: OS/2.usWeightClass = 275
- Hairline: OS/2.usWeightClass = 250
If you want the CSS to do "the right thing" when you set font weight in CSS, you have to map those CSS font weight to a real resource (which can have a completely different actual font weight) using @font-face rules:
/* Four different rules, for CSS weights 100, 200, 300, 400, same font name */
@font-face {
font-family: Lato;
font-weight: 100;
src: local("Lato Hairline"),
url("...latohairline.woff2") format(WOFF2);
}
@font-face {
font-family: Lato;
font-weight: 200;
src: local("Lato Thin"),
url("...latothin.woff2") format(WOFF2);
}
@font-face {
font-family: Lato;
font-weight: 300;
src: local("Lato Light"),
url("...latolight.woff2") format(WOFF2);
}
@font-face {
font-family: Lato;
font-weight: 400;
src: local("Lato Regular"),
url("...latoregular.woff2") format(WOFF2);
}
And now your CSS, when using the font family "Lato", will use the correct resource (according to you) based on the CSS font-weight property.
html, body {
font-family: Lato;
}
h1 {
font-size: 150%;
font-weight: 200;
}
p {
font-weight: 400;
}
...
(2019 edit: changed the font-face to use woff2, because that's the only format you should use by now).