Skip to content

Spacing scale as CSS variables (--mw-space-*) in sass/spacing.css - #670

Merged
wuda-io merged 1 commit into
materializecss:v2-devfrom
PetriLahdelma:spacing-scale
Oct 12, 2026
Merged

wuda-io merged 1 commit into
materializecss:v2-devfrom
PetriLahdelma:spacing-scale

Conversation

@PetriLahdelma

Copy link
Copy Markdown

As discussed in #665: the spacing scale as native CSS variables in a separate file, with screenshots.

sass/spacing.css (new, forwarded from materialize.scss after the M3 tokens):

:root {
  --mw-space-0: 0;
  --mw-space-1: 0.25em;
  --mw-space-2: 0.5em;
  --mw-space-3: 0.75em;
  --mw-space-4: 1em;
  --mw-space-5: 1.5em;
  --mw-space-6: 3em;
}

$spacing-values now points at these variables, so the m-* and p-* helpers follow any client-side override.

The six declarations that were off the scale. Your root font size is 14px, so the steps are 3.5, 7, 10.5, 14, 21 and 42px. My comment in #665 assumed 16px; at 14px three of the nearest steps are different, so I used those:

Where Before After Computed at 14px
blockquote margin 20px 0 var(--mw-space-5) 0 20px to 21px
.page-footer margin-top 5rem var(--mw-space-6) 70px to 42px, as you suggested
.footer-copyright padding 10px 0px var(--mw-space-3) 0 10px to 10.5px
td, th padding 15px 5px var(--mw-space-4) var(--mw-space-1) 15px 5px to 14px 3.5px
.responsive-table thead tr padding 0 10px 0 0 0 var(--mw-space-3) 0 0 10px to 10.5px
.responsive-table tr padding 0 10px 0 var(--mw-space-3) 10px to 10.5px

Helper classes. At the 14px root, em and rem give the same result, so .p-1 to .p-6 and the margin helpers render exactly as before in normal text. The difference is inside an element with its own font size, such as a heading or a small chip: there the helpers now scale with that text. That is what em means, and it may be worth a line in the release notes.

Screenshots of v2-dev and this branch side by side, built with npm run build. The responsive table is shown below 992px.

Light:

light

Dark:

dark

npm run lint and npm test (50 tests) pass.

The $spacing-values steps become --mw-space-0 to --mw-space-6 in :root, in
em, in a separate sass/spacing.css forwarded from materialize.scss. The map
points at the variables, so the m-* and p-* helpers follow a client-side
override. Six declarations in _global.scss that were off the scale now use
the nearest step at the 14px root (blockquote, footer, footer copyright,
table cells, responsive table rows); the footer margin snaps to 3em.

Refs materializecss#665
@wuda-io

wuda-io commented Oct 12, 2026

Copy link
Copy Markdown
Member

ok LGTM

@wuda-io wuda-io left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wuda-io
wuda-io merged commit 15898e7 into materializecss:v2-dev Oct 12, 2026
1 check passed
PetriLahdelma added a commit to PetriLahdelma/stylelint-plugin-rhythmguard that referenced this pull request Oct 14, 2026
scale: "auto" reads --spacing-xs..2xl from @mozilla-protocol/tokens, and
the Mozilla Protocol benchmark row is measured against 7.0.0 (19 off-scale),
as a Protocol contributor pointed out in mozilla/protocol#1132. The
playground bundle is rebuilt for the new allowlist entry. The outreach log
records the merge of materializecss/materialize#670.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PetriLahdelma added a commit to PetriLahdelma/stylelint-plugin-rhythmguard that referenced this pull request Oct 14, 2026
scale: "auto" reads --spacing-xs..2xl from @mozilla-protocol/tokens, and
the Mozilla Protocol benchmark row is measured against 7.0.0 (19 off-scale),
as a Protocol contributor pointed out in mozilla/protocol#1132. The
playground bundle is rebuilt for the new allowlist entry. The outreach log
records the merge of materializecss/materialize#670.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants