Skip to content
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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Fonts-weight descriptor #36686

wants to merge 13 commits into from

Conversation

estelle
Copy link
Member

@estelle estelle commented Nov 7, 2024

Replaces #32853
Fixes #32619

@estelle estelle requested a review from a team as a code owner November 7, 2024 09:17
@estelle estelle requested review from chrisdavidmills and removed request for a team November 7, 2024 09:17
@github-actions github-actions bot added the Content:CSS Cascading Style Sheets docs label Nov 7, 2024
@estelle estelle requested a review from wbamberg November 7, 2024 09:17
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Nov 7, 2024
Copy link
Contributor

github-actions bot commented Nov 7, 2024

Preview URLs

External URLs (2)

URL: /en-US/docs/Web/CSS/@font-face/font-weight
Title: font-weight

(comment last updated: 2024-11-13 18:04:58)

@estelle estelle changed the title Fonts; replaces 32619 Fonts-weight descriptor Nov 7, 2024
@estelle estelle requested review from a team and wbamberg and removed request for wbamberg November 7, 2024 09:20

{{embedlivesample("Selecting normal and bold fonts", "", 300)}}

### Setting font-weight ranges
Copy link
Collaborator

@wbamberg wbamberg Nov 8, 2024

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.

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.
Copy link
Collaborator

@wbamberg wbamberg Nov 8, 2024

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?

Copy link
Member Author

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.

Copy link
Collaborator

@wbamberg wbamberg Nov 9, 2024

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?

Copy link
Collaborator

@wbamberg wbamberg Nov 9, 2024

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.

Copy link
Member Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

font-weight page doesn't explain whether it is possible to set a range, or if so, how
2 participants