-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fonts-weight descriptor #36686
base: main
Are you sure you want to change the base?
Fonts-weight descriptor #36686
Conversation
Preview URLs External URLs (2)URL:
(comment last updated: 2024-11-13 18:04:58) |
|
||
{{embedlivesample("Selecting normal and bold fonts", "", 300)}} | ||
|
||
### Setting font-weight ranges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the point of this example. Why would someone want to use a range here?
ISTR when I looked into this the only use case I could see for a range was to limit the weights available in a variable range font.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've actually seen this done in the wild. redacted had 6 different font names for the same font in different ranges, and they updated the font-family name for every font-weight property. People do it, so we need to demonstrate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what's the use case for it? As someone trying to learn this feature, I look at this and think, why would anyone want to do this, what does it accomplish?
People do it, so we need to demonstrate it.
I'm not sure I agree with this. People do all kinds of things, but we should demo sensible use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this:
redacted had 6 different font names for the same font in different ranges, and they updated the font-family name for every font-weight property.
...isn't what's happening here, is it? This has the same font-family name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no; here we are using one font family name. I'll add to the pre-explanation.
|
||
In this example, we include the same two fonts as in the example above, but we set the `font-weight` descriptors to a different ranges. | ||
|
||
While this example is a bit contrived, it demonstrates how authors can include multiple fonts for multiple font-weights (and font-styles), by including multiple `@font-face` declarations with the same `font-family` value. In the rest of your stylesheets, you can then declare a `font-weight` (or `font-style`), and know the appropriate font will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm being thick, but the previous example demonstrates this use case as well, doesn't it? (and is not contrived, AFAIK it is showing the main use case for font-weight
). So what is the point here of using a range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if you do a bunch of fonts weights, such as : 300, 400, 500, 600, etc. and one of your devs writes 350, and you want to control which font the browser chooses in such a case, this does that. The previous example is only "normal" and "bold", or 400 and 700. Which should be chosen at 550 in the previous example? putting a range defines that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I think that makes sense! But then I still don't understand why the second range is a subset of the first. Why do we want to select the non-bold font when the dev writes 1000
?
I also wondered if you could do this without ranges, like this:
@font-face {
font-family: "Fira Sans";
font-weight: 1;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Light.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 200;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Regular.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 400;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Bold.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 900;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-ExtraBold.woff2");
}
What do ranges give you over this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this^ gives some results that I would not (naively) expect, in particular font-weight: 600;
selected extrabold.
With something like this:
@font-face {
font-family: "Fira Sans";
font-weight: 1 199;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Light.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 200 399;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Regular.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 400 899;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-Bold.woff2");
}
@font-face {
font-family: "Fira Sans";
font-weight: 900;
src: url("https://mdn.github.io/shared-assets/fonts/FiraSans-ExtraBold.woff2");
}
... I get the results I was expecting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i used something similar to your example; the ranges are slightly broader so i can explain the cascade (and so we don't need to clarify 399.5)
Replaces #32853
Fixes #32619