Skip to content

Global Styles: Consider supporting gap #32366

@jasmussen

Description

@jasmussen

What problem does this address?

Margins are good for spacing out items. However in many cases, gap (see details) provides a much better experience for laying out items.

Instead of spacing items by providing margins on child elements, a gap as applied to the container defines how much space is between the child elements.

This illustration, courtesy of CSS-tricks, showcases very well how it works:

before

While it can accomplish the same, there are a few benefits. Here, the navigation block is shown with a few menu items, spaced using margin, and in various justifications:

image

In this screenshot, the light red items have right-margins applied to space items out, and then uses :last-child to nullify the right-most margin. But this quickly makes for some growing complexity:

  • If the navigation items wrap, then the last-child will no longer be the right-most item.
  • If the navigation has a different justification, margins will need further adjusting.
  • While much of the RTL context is handled by the build system in the block editor, for themes needing to override values, they would have a harder time.

What is your proposed solution?

Using gap (shorthand for column-gap and row-gap) removes all of those headaches, simplifying the CSS and making it more predicactable, yet can still accomplish exactly the same. Only, you no longer have to worry about last-child or RTL considerations, and you have only a single property to consider for spacing out items inside.

Note that the gap needs to be applied to the container instead of the child items, and it need for that container to be a flex or grid item. However as a property supported in global styles for containers such as navigation, buttons or group, it could make for an excellent solution.

It would need some visual explorations for how it need be surfaced in the UI. Since the Buttons block already uses gap to space buttons out, though, it might be worth surfacing the feature in theme.json even before a UI was made available.

Metadata

Metadata

Assignees

Labels

Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.jsonNeeds DesignNeeds design efforts.Needs Design FeedbackNeeds general design feedback.[Block] GroupAffects the Group Block (and row, stack and grid variants)[Block] NavigationAffects the Navigation Block[Block] SocialAffects the Social Block - used to display Social Media accounts[Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Status] In ProgressTracking issues with work in progress

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions