Visitar URL original
USWDS - Range slider: Fix webkit thumb centering after border increase by ethangardner · Pull Request #6814 · uswds/uswds · GitHub
Skip to content

USWDS - Range slider: Fix webkit thumb centering after border increase - #6814

Merged
ethangardner merged 2 commits into
developfrom
fix/range-slider-thumb-centering
Aug 14, 2026
Merged

ethangardner merged 2 commits into
developfrom
fix/range-slider-thumb-centering

Conversation

@ethangardner

@ethangardner ethangardner commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixed off-center range slider thumb in Chromium and Safari by correcting the margin-top offset on ::-webkit-slider-thumb to account for the track border width increase introduced in #6811.

Breaking change

This is not a breaking change.

Related issue

Closes #6813

Related pull requests

Depends on / follows #6811 (range slider track border width increase).

Preview link

Preview link: N/A

Problem statement

The range slider track border was widened from 1px to 2px in #6811 (commit 726e7750a), but the webkit-specific margin-top correction on ::-webkit-slider-thumb was not updated to match.

::-webkit-slider-runnable-track uses content-box sizing, so its rendered height equals height + border-top + border-bottom:

The -3px offset was calibrated to the 18px track. With a 20px track, the thumb sat 1px below center in Chromium and Safari at every viewport and container width.

Solution

Updated the margin-top offset from -3px to -4px on ::-webkit-slider-thumb. Replaced the // magic number comment with a full geometric explanation so the value can be maintained correctly when the track border changes in the future.

This is a one-line Sass change. No markup, JavaScript, or settings are affected.

Testing and review

  1. Build USWDS and open the Range component Storybook story.
  2. View in Chromium (Chrome/Edge) and Safari — the thumb should be vertically centered on the track at all viewport widths.
  3. Confirm Firefox is unaffected (Firefox uses ::-moz-range-thumb, which has its own rule and was not changed).

The track border was widened from 1px to 2px in 726e775 but the webkit-
specific margin-top correction on ::-webkit-slider-thumb was not updated.

::-webkit-slider-runnable-track uses content-box sizing, so its rendered
height = height property + border-top + border-bottom:

  v3.13.0: 16px + 1px + 1px = 18px
  develop: 16px + 2px + 2px = 20px (track grew 2px)

The -3px offset was calibrated to the 18px track. With a 20px track the
centreline is 1px lower, so the thumb sat 1px below centre in Chromium and
Safari at every viewport and container width.

Updated to -4px and replaced the 'magic number' comment with an explanation
of the geometry so the value can be maintained correctly in future.

Fixes #6813
@github-actions

Copy link
Copy Markdown
Contributor

✅ All commits on this PR have a verified signature. Thanks!

The previous comment stated the formula as -(border-width), which implied
the -4px value was simply the current 2px border. That is wrong.

The correct formula is -(border_width + 2px), where the +2 is a fixed
geometric constant. Verified empirically:
  border=1px (v3.13.0) → -3px
  border=2px (current)  → -4px

Updated the comment to state the formula accurately and explain that the
constant 2 is border-independent.
@ethangardner
ethangardner merged commit 9924244 into develop Aug 14, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Triage to Fed Final Review in USWDS Core Project Data Aug 14, 2026
@ethangardner
ethangardner deleted the fix/range-slider-thumb-centering branch August 14, 2026 22:21
@chandracarney chandracarney moved this from Fed Final Review to Done in USWDS Core Project Data Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

USWDS - Range slider: webkit thumb sits 1px low after track border increased to 2px

3 participants