Skip to content

Typography: Fix link font-size inheritance when block typography is customized#77458

Open
dpmehta wants to merge 1 commit intoWordPress:trunkfrom
dpmehta:fix/link-global-styling-override-issue
Open

Typography: Fix link font-size inheritance when block typography is customized#77458
dpmehta wants to merge 1 commit intoWordPress:trunkfrom
dpmehta:fix/link-global-styling-override-issue

Conversation

@dpmehta
Copy link
Copy Markdown
Contributor

@dpmehta dpmehta commented Apr 17, 2026

What?

Closes #64976

This PR resolves an issue where custom typography font sizes applied to a block (via Inspector Controls) are ignored by the block's inner links if a global link font size has been defined in the Site Editor.

Why?

When a site-wide link font size is defined in Global Styles (Editor > Styles > Typography > Elements > Links), WordPress outputs an explicit styling rule: a:where(:not(.wp-element-button)) { font-size: ... } which carries a specificity of 0-0-1.

When a custom typography size is applied to a block, Gutenberg targets the block's wrapper (e.g., via a .has-large-font-size class or an inline style="..." attribute). Because the inner <a> element has a dedicated CSS rule targeting it via Global Styles, it fails to inherit the font size from its parent wrapper, creating visual inconsistencies where links don't match the surrounding block text.

How?

  • Global Cascade Reset (packages/block-library/src/common.scss): Added a targeted :where() selector to capture wrappers containing custom typography features (.has-custom-font-size, [class*="-font-size"], and [style*="font-size"]). This rule forces inner anchor tags to font-size: inherit;. Wrapping it in html :where(...) provides exactly 0-0-2 specificity—strong enough to override the global 0-0-1 link rule, but weak enough to not disrupt any utility classes applied directly to the anchor elements themselves.

Testing Instructions

  1. Using a block theme (e.g., Twenty Twenty-Five), go to Site Editor > Styles > Typography > Elements > Links, and set the Font Size to Large.
  2. Edit a page or template, create a Paragraph block, and insert a hyperlink into the body text.
  3. Select the Paragraph block and change its typography Font Size to Small via the Inspector Controls.
  4. Verify that the link text shrinks to properly match the Small size of the paragraph instead of staying stubbornly Large.

Screenshots or screencast

Before Fix

before-fix.mov

After Fix

after-fix.mov

Use of AI Tools

AI was used to investigate the exact CSS specificity clash causing the inheritance breakdown and draft this PR description.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Apr 17, 2026
@dpmehta dpmehta marked this pull request as ready for review April 17, 2026 17:47
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block library, Global Styles.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dpmehta <mehtadev@git.wordpress.org>
Co-authored-by: NikoVee <nikov@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If you set a global link font size in the FSE editor and styles you can't overwrite it with blocks

2 participants