Labels stretch across a stack when a flex or grid container lets its children grow to fill cross-axis space, when an SVG text element inherits a viewBox scale, or when a charting library's axis band assigns the label the full plot width. The fix depends on which of those three sources you're hitting, and the fastest way to tell them apart is to inspect one label's computed width against its text content. If the box is wider than the glyphs, you have a layout problem. If the glyphs themselves look wide and thin, you have a scaling problem. Most of the time you'll land in the first bucket, and a single alignment or width rule resolves it.
This guide walks through the diagnosis, then the fixes in the order you should try them: from the cheapest CSS corrections to the structural changes you'd only make if the layout model itself is wrong. It assumes a web stack (HTML/CSS, SVG, or a charting library), since that's where "stack" and "label" collide most often, but the reasoning transfers to any layout engine that has flex-like stretching behavior.
Why labels stretch in the first place
Three mechanisms account for nearly every case you'll encounter.
Flex stretch on the cross axis. In a column flex container, the default align-items: stretch makes every child as wide as the container. A label that is a block-level child of that column gets the full width whether or not its text needs it. The text itself doesn't grow—but if the label is also text-align: justify, or if it's inside a or badge with width: 100%, the visible result reads as stretched.
Grid track filling. A grid item placed in a 1fr column stretches to fill that track unless you set justify-self. If you've built a "stack" of cards in a single-column grid, every label inside those cards inherits the full track width.
SVG and chart band scaling. When an SVG has a viewBox and preserveAspectRatio set to something other than none, the whole coordinate system scales, so text drawn at a fixed font size appears to stretch horizontally if the aspect ratio changes. Charting libraries add their own layer: a category axis may assign each label the entire band width, and if the label is rendered as a with textLength set, the browser will stretch the glyph spacing to hit that length exactly. That's the only case where the characters genuinely deform rather than just occupying a wide box.
Knowing which one you're facing changes the fix entirely, so start there.
Diagnose first: box width versus glyph width
Before changing any code, select one problematic label in your browser's developer tools and read the box model.
If the content box is wide but the text is left-aligned and looks normal, the label is simply occupying available space. That's layout stretch, and it's usually harmless unless a border, background, or hover target makes it visible. If the text is centered in a wide box, it will look detached from its row—that's the symptom people usually mean.
If the glyphs themselves are wide, spaced out, or thin, check whether the element or an ancestor has textLength, letter-spacing at a large value, or a transform scale with a non-uniform x factor. Non-uniform scaling (for example transform: scaleX(1.4)) is a common culprit in older chart code and in CSS applied to SVG text.
One quick check: temporarily set outline: 1px solid red on the label. If the outline hugs the text, the box is fine and the problem is glyph-level. If the outline spans the whole column, it's layout stretch.
Fix 1: change the cross-axis alignment on the stack container
This is the highest-leverage fix and it costs one line. On the flex column that holds your stacked items:
align-items: flex-start stops children from stretching to the container width. Use center if you want the labels horizontally centered but still sized to their content. If you need per-child control, keep stretch on the container and set align-self on the individual label.
The trade-off: changing align-items affects every child, not just labels. If your stack also contains full-width dividers, images, or buttons that rely on stretching, you'll need to give those children align-self: stretch explicitly. That's usually a cleaner outcome than fighting the default on every label, but it is a container-level decision, so check the whole stack before committing.
If the stack is a grid rather than a flex column, the equivalent is justify-items: start on the container, or justify-self: start on each label. For a single-column grid, justify-items: start prevents each item from filling the track.
Fix 2: constrain the label itself
When you can't or shouldn't touch the container, size the label directly. width: fit-content (or max-content if you want it to never wrap) makes the element shrink to its text regardless of the parent's stretch behavior. max-width caps how far it can grow. display: inline-block pulls the element out of block-flow stretching in many contexts.
For a label that should occupy only part of a row, flex: 0 1 auto on a flex child plus min-width: 0 prevents the child from expanding beyond its content while still allowing it to shrink and truncate. That min-width: 0 is the detail people miss: flex items have an automatic minimum size of auto, which means a long unbreakable string can force the item wider than you intended.
If the label is a badge or pill and you want it to keep its shape, width: max-content plus white-space: nowrap is the standard combination. Add text-overflow: ellipsis and overflow: hidden only if truncation is acceptable for the longest strings; otherwise the badge will grow, which may be the right behavior.
One thing to watch: fit-content and max-content behave differently when the text contains forced line breaks. A label with
inside will size to its longest line under max-content, while fit-content will shrink toward the available width and wrap. Pick based on whether you want the label to wrap at all.
Fix 3: stop text-align and justify from widening the appearance
If the box is legitimately full-width and you want the text to sit at the left edge, text-align: left is the fix, not a width change. text-align: justify on a single short line has no effect, but on a label that wraps to two lines it will spread the final line—and on some engines, the last line of a justified block gets stretched if text-align-last is also justify. Set text-align-last: left explicitly if you use justification anywhere near labels.
A subtler case: letter-spacing inherited from a heading style. If a parent sets generous tracking for display type and labels inherit it, short labels look airy and long ones look stretched. Reset letter-spacing: normal on the label class rather than trying to compensate with narrower text.
And check word-spacing and font-stretch. Variable fonts with a font-stretch axis will genuinely widen glyphs, and if a label class inherits a stretch value from a theme, that's a real deformation, not a layout artifact.
Fix 4: handle SVG text scaling and viewBox stretch
If the labels live inside an SVG, the container-level flex fixes won't help. The relevant controls are viewBox, preserveAspectRatio, and per-element textLength.
A viewBox that doesn't match the rendered aspect ratio, combined with preserveAspectRatio="none", will scale x and y independently and stretch everything inside, text included. Switching to the default xMidYMid meet preserves proportions and letterboxes instead. If you need the graphic to fill the box exactly, accept that text will scale; better, render labels in HTML overlaid on the SVG so they're immune to the coordinate transform.
textLength on a element forces the rendered text to exactly that length, and lengthAdjust controls whether the browser stretches spacing (spacing, the default) or the glyphs themselves (spacingAndGlyphs). If a chart library emits textLength for axis labels to make them fill the band, removing that attribute or setting it to the measured text width fixes the deformation. You can measure with getComputedTextLength() in the browser and set the attribute explicitly if you still want a fit-to-width behavior that doesn't distort.
For SVG text inside a scaled with a transform, remember that transforms apply to the rendered output, so a scale(1.2, 1) on a group stretches its text horizontally. Move the transform to a shape-only group and keep labels in an untransformed layer.
Fix 5: correct charting-library axis behavior
Charting libraries each handle category labels a little differently, and the "stretched across the stack" symptom in a chart usually means the axis is assigning the full band to each label.
In D3-based charts, a band scale's bandwidth() is the full slot, and labels are typically centered within it by default—they aren't stretched, but they can look detached in a stacked bar chart where each series has a narrow band. Rotating labels, reducing font size, or switching to a hierarchical axis are the usual remedies; setting text-anchor to start or end shifts them to the band edge, which often reads better in dense stacks.
In Chart.js, the category axis has ticks.autoSkip and ticks.maxRotation, plus padding controls. Labels don't stretch, but a very wide canvas with few categories can make them appear spaced out; tightening ticks.padding and enabling autoSkip addresses the visual result. For horizontal bar charts, indexAxis: 'y' puts categories on the vertical axis, which usually eliminates the crowding problem entirely.
In libraries that render labels as HTML (Recharts, Victory, and similar React wrappers), the label often inherits a wrapper
that carries the full band width. The fix is the same CSS as Fix 1 applied to the library's label class—width: max-content or align-self: center.
The stop condition here: if the library's label positioning is driven by internal layout code you can't override with CSS, and the chart is central to the product, it's worth checking whether a newer major version changed the behavior before writing a custom renderer. Library internals shift between versions, so verify against the version you actually have installed rather than assuming current docs match.
Fix 6: structural changes when the layout model is wrong
Sometimes the label stretching is a symptom of a container doing two jobs. A common pattern is a "stack" component that's supposed to be a vertical list of rows but is built as a column flex container with stretch, and each row's label is meant to be a left-aligned title with a right-aligned value. People then fight the stretch on the label when the real fix is to make each row a flex row with justify-content: space-between and let the label be an ordinary flex child.
If you're seeing stretch across many components, audit the container: is it a stack (vertical list) or a row (horizontal pair)? Labels in rows should be flex children with flex: 0 1 auto, not block children of a column. Splitting the component usually removes the need for any per-label hacks.
The other structural case is text that must fill a fixed-width slot, like a value display in a dashboard. There, stretch is intentional and the real issue is font size—use font-size: clamp() or a container query to scale the type with the slot, rather than letting a fixed size sit in a wide box.
A worked check: does the fix hold under load
After applying a fix, test three things rather than one. First, the shortest possible label (a single character) — it should not stretch to the container width. Second, the longest realistic label — it should either wrap, truncate, or grow the container, per your design decision, and not overflow silently. Third, a label with mixed content, like a name plus a count, since inline elements inside the label can reintroduce stretching if they're block-level.
Resize the viewport across your breakpoints, because a fix that works at desktop widths can break when a media query flips the stack to a row. And check the label inside its hover and focus states if it's interactive—a focus ring on a stretched box reveals the problem you thought you'd fixed.
A simple pass/fail: the label's rendered box should be no wider than its longest unbreakable word plus your horizontal padding, unless a parent has an explicit width you set on purpose. If it's wider, something upstream is still stretching it, and you can walk up the ancestor chain turning on outlines until you find the container responsible.
When the stretching is actually correct
Not every wide label is a bug. A full-width clickable row in a settings list needs its hit target to span the row, so the label element should be wide and the text inside left-aligned. The same applies to table cells, form field rows with a right-aligned hint, and navigation items with a trailing chevron. In those cases the fix isn't to shrink the label but to separate the text from the interactive surface—wrap the text in a that sizes to content, keep the outer element full-width, and style accordingly. That distinction between the interactive box and the typographic element resolves a lot of "stretched label" reports without changing the layout at all.
FAQ
Why does my label stretch only in Safari? Flex and grid cross-axis behavior is well standardized now, but older Safari versions handled min-width: auto on flex items differently, and SVG textLength rendering has historically varied. Check the computed align-items value first; if it's normal, the engine may be resolving it as stretch in the column direction, which is correct behavior and needs an explicit override.
Does display: inline-block fix stretched labels inside a grid? Not on its own. A grid item's stretch comes from justify-self and align-self, which apply to the item regardless of its inner display type. Set justify-self: start on the item, then let its inner display be whatever the content needs.
My chart labels look stretched but the CSS is fine. What else? Look for textLength and lengthAdjust in the generated SVG markup, and check whether the chart's has preserveAspectRatio="none". Both are rendering-level causes that CSS can't override, so you'll need to change the chart configuration or post-process the markup.
Can text-wrap: balance help with wrapping labels? It can make multi-line labels look more even, but it doesn't prevent stretching. It's a useful companion to max-width on labels that must wrap, not a substitute for fixing the stretch source.