Skip to content

Enable viewport specific root styles #87086

Open

Description

@henriqueiamarino

What problem does this address?

Root padding (Styles > Layout > Padding, styles.spacing.padding with useRootPaddingAwareAlignments) is the single place where a theme sets the side margins of the page. Every block that uses the global padding inherits it.

It holds one value for all viewports. A generous desktop margin, for example 15%, leaves too little room on a phone, and a phone-friendly value looks cramped on desktop.

Responsive style states (@tablet, @mobile) already solve this for blocks and elements, but they are not accepted on root styles. The workarounds today are:

- Repeat responsive padding on every top-level block. It works until a user adds or removes one of those blocks, and then the page is misaligned. It also moves a global decision into many local ones.
- Put a CSS function such asclamp()in theme.json. The Styles UI cannot display or edit it, so the value is no longer manageable from the Editor.
Neither keeps the decision where it belongs, in the Layout settings.

Current behaviour

Tested on WordPress 7.2-beta5, without the Gutenberg plugin.

{
	"version": 3,
	"settings": { "useRootPaddingAwareAlignments": true },
	"styles": {
		"spacing": { "padding": { "left": "15%", "right": "15%" } },
		"@tablet": { "spacing": { "padding": { "left": "32px", "right": "32px" } } },
		"@mobile": { "spacing": { "padding": { "left": "16px", "right": "16px" } } },
		"blocks": {
			"core/group": {
				"@tablet": { "spacing": { "padding": { "left": "11px" } } }
			}
		}
	}
}
  • The block-level state is kept and output as expected: @media (480px < width <= 782px){:root :where(.wp-block-group){padding-left: 11px;}}
  • The root-level @tablet and @mobile keys are removed when the data is sanitized. Only the base value is output: --wp--style--root--padding-right: 15%; --wp--style--root--padding-left: 15%;
  • In the Site Editor, Styles > Layout shows one Padding control with no viewport state.

What is your proposed solution?

  1. theme.json: accept @tablet and @mobile on top-level styles, at least for spacing.padding, and output the --wp--style--root--padding-* custom properties inside the matching media queries. spacing.blockGap and root typography would be natural follow-ups.
  2. Styles UI: give Styles > Layout the same viewport state control that block styles already have, so Padding (and Block spacing) can be set for Desktop, Tablet and Mobile.
  3. Later, if it makes sense: per-viewport Content width and Wide width. These are settings, not styles, so they are probably a separate discussion.

Why it matters for themes

Page margins are one of the most common things a design changes between desktop and mobile. With root padding fixed to one value, block themes have to choose between an Editor-friendly setting that is wrong on some screens and a correct value that the Editor cannot manage.

Related

Tracking issue for responsive style states: #85243. This case is not listed there yet.
#82392, a similar gap where @tablet and @mobile were ignored in block style variation partials.

Activity

  1. added
    [Type] Enhancement
    on Nov 19, 2026
  2. added
    [Feature] Style States
    on Nov 19, 2026
  3. changed the title [-][Type] Enhancement, [Feature] Style States, Global Styles[/-] [+]Enable viewport specific root styles[/+] on Nov 19, 2026
  4. tellthemachines commented on Nov 19, 2026

    @tellthemachines
    Contributor

    Thanks for writing this up @henriqueiamarino; I'll add it to the style states tracking issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Style States[Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions