Skip to content

Fluid typography: add font size constraints  #44957

@ramonjd

Description

@ramonjd

Parent issue:

What problem does this address?

Where fluid typography is enabled, minimum and maximum font sizes in presets can be calculated according to defined min and max values, e.g.,

{
    "size": "2rem",
    "fluid": {
        "min": "2rem",
        "max": "2.5rem"
    },
    "slug": "medium",
     "name": "Medium"
 },

For the above preset, the font size, regardless of the viewport, will not be larger than 2.5rem and it will not be smaller than 2rem.

Where min and max values are not supplied, either in theme.json font size presets or as a custom font size in styles, the min and max values are calculated from the size itself, e.g., minFontSize * DEFAULT_MINIMUM_FONT_SIZE_FACTOR.

Where the size is itself very large or very small, this could lead to readability issues in certain viewports.

2022-10-14.12.49.49.mp4

The use of em for example might also cause issues if the relative parent's font size is set very small.

What is your proposed solution?

Add default minimum (and maximum?) font size limits so that text does not become smaller than n1 or bigger than n2.

Proposed minimum font size is 14px/0.875rem/0.875em.

The default limits can be configurable to allow themers more control and added in conjunction with:

❗ What do we do with font sizes < 14px?

Users may define font-sizes that are smaller than 14px. IThe user-defined font size could be the minimum in a clamped value. For example if a user defines 9px for a block, then the minimum font size for that block will be 9px and a clamped value will be generated.

OR

Where users define font-sizes that are smaller than 14px in the editor or theme.json, and there is no specified minimum the value is not clamped (no fluidity).

cc @jasmussen @jffng

Metadata

Metadata

Assignees

Labels

[Feature] TypographyFont and typography-related issues and PRs[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions