Repository navigation
Idea: fluid root font-size in the generated globals.css (scale the whole UI on large screens) #12699
rdehnhardt
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
shadcn/ui is rem-based end to end (Tailwind spacing/type utilities,
--radius). That means a single fluid value on the root scales every component proportionally on large monitors (type, spacing, radii) without touching any component. I'd like to propose adding it to the base layer generated byshadcn init.Proposal
reminside media queries resolves against the initial font size, sosm:/lg:still fire at 640/1024px.Motivation
There is no "standard" screen anymore. The same shadcn app is opened on 320px phones, 13" laptops, 27" 1440p monitors, 4K displays at 100% OS scaling and 21:9 ultrawides. A layout tuned for one reference width either looks cramped on small screens or tiny and half-empty on large ones.
Breakpoints only cover a few widths.
sm:through2xl:jump at five fixed widths and stop at 1536px. Everything between two breakpoints, and everything above the last one, gets no adjustment at all. A fluid root scales smoothly at every width and needs no extra classes.Why
remand notpx:pxis a fixed size. It doesn't relate to the screen, to the rest of the layout, or to the user.remis relative to a single value, the root font size. Change that value and every rem-based measurement (type, spacing, radii, component heights) scales together, keeping the design's proportions intact.remrespects the user's default font size setting in the browser.pxoverrides it, which is an accessibility problem in itself.Today every project works around this on its own: overriding the root size (related: #9778) or sprinkling
2xl:variants everywhere. A sensible default would solve it once, for everyone.Accessibility
Pure
vwfont sizes don't respond to browser zoom, which can fail WCAG 1.4.4 (Resize Text). The formula above addresses this in two ways:rem + vw, so browser zoom and the user's default font size still apply;Known limitation:
pxvalues inside shadcn/ui itselfThe proposal only works for values expressed in
rem. Anything hardcoded inpxstays the same size while everything around it grows, so the proportions drift on large screens. Some of this exists in the registry today:w-[...px],max-h-[...px],text-[...px]). For example, the chart examples size their containers withmax-h-[250px].innerRadius={80},outerRadius={140},tickMargin={8},strokeWidth={2}), and CSS can't reach those.px.So this would need a small audit of the registry, replacing dimensional
pxvalues withremequivalents (max-h-[250px]→max-h-[15.625rem]). Below 1800px nothing changes either way, so the audit can happen gradually and doesn't block the proposal. I'm happy to do that pass as part of the PR.Hairlines are a separate question. Tailwind's
border,ringandh-pxutilities are defined inpxby Tailwind itself, so 1px borders and separators won't grow with the root. Ideally they would scale too (1px=0.0625rem), but two things make this less urgent:Scaling them would mean overriding Tailwind's border utilities across every component, so I'd treat it as out of scope for a first version and open for discussion.
Trade-offs / open questions
shadcn init --fluid, or a commented-out block in globals.css)?Happy to open a PR if there's interest.
All reactions