Add rem-based sizing support to GlIcon for improved accessibility
Description
The GlIcon component currently uses fixed pixel values for icon sizing, which causes layout inconsistencies when users have non-default text sizes configured in their browser settings. Loading icons (which use rem values) can cause text to shift when they appear alongside icons using fixed pixel sizes.
Problem
When users configure non-default text sizes in their browser:
-
GlIconuses fixed pixel values in icon.scss: -
GlLoadingIconusesremvalues via design tokens in loading_icon.scss (e.g.,$gl-spacing-scale-5: 1rem,$gl-spacing-scale-6: 1.5rem)
This mismatch causes visual shifting and layout instability when a loading spinner replaces or appears alongside an icon.
Example scenario: In the file tree browser, when a folder expands, a loading spinner temporarily replaces the folder icon. Users with larger browser font sizes experience text shifting because the spinner scales with their preferences while the icon does not.
Related issue: gitlab-org/gitlab#587277
Proposal
Add support for rem-based sizing to the GlIcon component to ensure icons scale appropriately with user browser settings.
Proposed approaches (for discussion)
-
Switch to
remvalues directly - Replace fixed pixel values with equivalentremvalues (e.g.,16px→1rem). This provides immediate accessibility benefits but may cause unintended side effects in existing implementations. -
Introduce an optional property - Add a new prop (e.g.,
scaleWithTextoruseRemSizing) that enablesrem-based sizing when set totrue, defaulting to the current behavior for backward compatibility. - ...
Why this matters
- Accessibility: Users with visual impairments often increase their browser's default font size. Icons that don't scale with text can become disproportionately small and harder to perceive.
-
WCAG compliance: Supports
WCAG 1.4.4 (Resize text)by ensuring UI elements scale appropriately when text is resized up to 200%. -
Consistency: Aligns icon sizing behavior with the
GlLoadingIconcomponent, preventing layout shifts when icons and spinners are used interchangeably. - User experience: Provides a more cohesive experience for users who customize their browser settings for readability.
Checklist
Make sure the following are completed before closing the issue:
- Assign the correct component label to this issue.
- Create an MR with the additions or updates needed.
- Be sure to get your MR reviewed by a FE/UX Foundations designer.
- When applicable, create an MR in Pajamas to update the demos. If you do not have capacity to complete the demos, create an issue in Pajamas and bring the issue to your team planning session for prioritization and scheduling. Mark the issue as related to this one.
- When applicable, create an MR in Pajamas to update the component status.
- When applicable, create an issue in Pajamas using the "Component Documentation" issue template to update guidelines. Ping a designer on your team for awareness and bring the issue to your team planning meeting for prioritization and scheduling.
- When applicable, create an issue in Pajamas using the "Figma update" issue template to update the Figma UI Kit. Ping a designer on your team for awareness and bring the issue to your team planning meeting for prioritization and scheduling.
- When introducing a major or breaking change, communicate the changes within the Engineering Week in Review.
-
🎉 Congrats, you made it! You can now close this issue.