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

Set font size proportional to user's font size #92448

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Dec 30, 2021

According to MDN (https://developer.mozilla.org/en-US/docs/Web/CSS/font-size),

To maximize accessibility, it is generally best to use values that are relative to the user's default font size.

Defining font sizes in px is not accessible, because the user cannot change the font size in some browsers.

Note that changing font size (in browser or OS settings) is distinct from the zoom functionality triggered with Ctrl/Cmd-+. Zoom
functionality increases the size of everything on the page, effectively applying a multiplier to all pixel sizes. Font size changes apply to just text.

For relative font sizes, we could use em, as we do in several places already. However that has a problem of "compounding" (see MDN article for details). The compounding problem is nicely solved by rem, which make font sizes relative to the root element, not the parent element.

Since we were using a hodge-podge of pixel sizes, em, rem, and percentage sizes before, this change switches everything to rem, while keeping the same size relative to our old default of 16px.

16px is still the default on most browsers, for users that haven't set a larger or smaller font size.

Part of #59845. Note: this will conflict with #92404.

r? @GuillaumeGomez

Demo: https://rustdoc.crud.net/jsha/font-size-access/std/string/struct.String.html

@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 30, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 30, 2021
@jsha jsha added the A-rustdoc-ui Area: rustdoc UI (generated HTML) label Dec 30, 2021
@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

Looks reasonable, and https://caniuse.com/rem looks like it's sufficiently widely supported.

According to MDN
(https://developer.mozilla.org/en-US/docs/Web/CSS/font-size),

> To maximize accessibility, it is generally best to use values that
> are relative to the user's default font size.

> Defining font sizes in px is not accessible, because the user cannot
> change the font size in some browsers.

Note that changing font size (in browser or OS settings) is distinct
from the zoom functionality triggered with Ctrl/Cmd-+. Zoom
functionality increases the size of everything on the page, effectively
applying a multiplier to all pixel sizes. Font size changes apply to
just text.

For relative font sizes, we could use `em`, as we do in several places
already. However that has a problem of "compounding" (see MDN article
for details). The compounding problem is nicely solved by `rem`, which
make font sizes relative to the root element, not the parent element.

Since we were using a hodge-podge of pixel sizes, em, rem, and
percentage sizes before, this change switching everything to rem, while
keeping the same size relative to our old default of 16px.

16px is still the default on most browsers, for users that haven't set a
larger or smaller font size.
@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+

@bors
Copy link
Contributor

bors commented Jan 5, 2022

📌 Commit cc18120 has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 5, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 5, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92182 (Label more build steps)
 - rust-lang#92188 (rustdoc: Clean up NestedAttributesExt trait/implementation)
 - rust-lang#92322 (Add another implementation example to Debug trait)
 - rust-lang#92448 (Set font size proportional to user's font size)
 - rust-lang#92517 (Explicitly pass `PATH` to the Windows exe resolver)
 - rust-lang#92545 (Extract init_env_logger to crate)
 - rust-lang#92579 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5bf321f into rust-lang:master Jan 5, 2022
@rustbot rustbot added this to the 1.59.0 milestone Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: rustdoc UI (generated HTML) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants