Dashboards are viewed on wide monitors and narrow phones alike. In Recharts JS, responsiveness is handled by one component — ResponsiveContainer — plus a few layout rules that are easy to get wrong. This guide explains both.
How ResponsiveContainer works
ResponsiveContainer watches the size of its parent element and passes the measured width and height to the chart inside it. The chart itself no longer needs fixed dimensions:
import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, Tooltip } from "recharts";
<ResponsiveContainer width="100%" height={300}>
<AreaChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Area type="monotone" dataKey="value" stroke="#5B54D6" fill="#E5E3FB" />
</AreaChart>
</ResponsiveContainer>
The golden rule: the parent needs a height
Width is easy, because block elements stretch horizontally by default. Height is different: a div with no content has no height. If you write height="100%" and the parent has no explicit height, 100% of zero is zero and the chart disappears.
Three reliable patterns:
- Fixed pixel height –
height={300}on the container. Simple and predictable. - Parent with a height – give the wrapping element a height in CSS, then use
height="100%". - Aspect ratio – use the
aspectprop so height follows width.
// height follows width at 2:1
<ResponsiveContainer width="100%" aspect={2}>
<LineChart data={data}>{/* ... */}</LineChart>
</ResponsiveContainer>
Combine an aspect ratio with minHeight so charts stay readable on very narrow phones.
Charts inside CSS grid and flexbox
In grid or flex layouts, a chart can push its column wider than expected because the container measures before the layout settles. Setting min-width: 0 on the grid or flex child lets it shrink correctly:
.dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.dashboard > .card { min-width: 0; height: 320px; }
Mobile-friendly details
- Fewer ticks – use the
intervalorminTickGapprops onXAxisto avoid overlapping labels. - Shorter labels – format values with
tickFormatter(for example "12k" instead of "12,000"). - Tighter margins – reduce the chart
marginprop so the plot area uses the available width. - Hide the legend on small screens and rely on the tooltip, or move the legend below the chart.
Responsive charts in shadcn/ui
If you use shadcn/ui, its ChartContainer handles the responsive wrapper for you, but the same height rule applies: give it a minimum height or aspect ratio. Read more in the Recharts shadcn guide.
Quick checklist
- Container width is
100%. - Height is a number, an aspect ratio, or the parent has a real CSS height.
- Grid and flex children have
min-width: 0. - Axis ticks and labels are tuned for small screens.
Still seeing an empty space where your chart should be? The troubleshooting guide walks through every common cause.
Think in constraints rather than screen sizes
A responsive chart is one that respects the space available to it, not merely one that changes width when the browser window moves. The dimensions of a chart may be controlled by a dashboard card, a grid column, a sliding sidebar or the surrounding content. ResponsiveContainer observes its parent, so the parent must have useful dimensions. This is the central principle behind reliable Recharts layouts and the first thing to investigate when a chart unexpectedly disappears.
Fixed heights are often a practical starting point because they keep charts visible while their widths change. Aspect ratios can be useful when a consistent proportion suits the story being told, but should not make labels microscopic on narrow screens. For a dense time series, a minimum height may be more valuable than a strict ratio. Think of each chart as a component with explicit constraints and a purpose, rather than a picture that should always shrink uniformly.
Make grid and flex layouts predictable
CSS grid and flexbox distribute space in ways that can surprise developers. A child may retain an intrinsic minimum width, preventing a chart from shrinking even when the surrounding column becomes narrower. A grid track defined carelessly may overflow its container, and a nested flex child may need min-width: 0 to allow the browser to resolve its size correctly. Check the computed width of each ancestor when a chart seems wider than the card in which it belongs.
For height, distinguish between a fixed pixel value, a minimum height and a percentage resolved against a parent. A percentage cannot produce a meaningful final height when the chain of parents offers no defined reference. In these situations, adjusting the Recharts component will not repair the layout. Give the card an explicit height or minimum height, confirm the result in browser developer tools and then allow ResponsiveContainer to perform the measurement for which it was designed.
Curate information for smaller screens
Simply reducing the plot can cause axis labels to collide, legends to wrap unpredictably and tooltips to cover the series being inspected. A more considered mobile design edits the density of information. Display fewer x-axis ticks, abbreviate familiar month names and remove decorative elements that no longer serve the interpretation. Where a comparison requires several series, decide whether all of them remain useful at the smallest viewport or whether a simplified summary would communicate more effectively.
Do not hide units, legends or explanatory text merely to gain a few pixels. Those are the cues that make the graphic intelligible. A compact chart can still have a clear heading and a short contextual sentence. If readers need exact values for decisions, supply a table or accessible summary alongside the visual. Prioritise understanding over decorative symmetry. The effective mobile chart is not always a miniature desktop chart; sometimes it is an edited version of the same analytical story.
Account for interaction and accessibility
Hover behaviour is natural on desktop but unreliable as the primary interaction on touchscreens. Test tooltip positioning with fingers rather than only with a mouse cursor. Ensure that the overlay does not extend beyond the viewport or obscure the data point it describes. When chart interactions reveal critical information, offer an alternative that does not demand precise pointer movements. Responsive design includes input methods as well as dimensions.
Review text contrast and scale at device zoom levels, not only at one nominal resolution. Labels that are visible at a standard desktop size may become uncomfortable when a narrow device displays several series. Keep focus styles understandable and avoid changing the meaning of colours between breakpoints. Accessibility should be preserved while the layout changes. A responsive interface that can be navigated and understood by more people is a stronger product than one that merely passes a width-based screenshot test.
Test the difficult states deliberately
Build a small testing matrix that covers a wide monitor, an ordinary laptop, a narrow phone and an intermediate viewport where responsive grids often change columns. Include empty data, unusually large values, long category names and a legend with multiple entries. Watch for clipped labels, collapsed heights and unexplained horizontal scrolling. If the chart is inside a hidden tab or disclosure panel, verify that it measures its dimensions properly when the panel becomes visible.
Also test what happens after the layout changes dynamically. A collapsible sidebar or a resizable panel may affect container measurements without changing the entire page. Use the browser’s layout inspection tools to establish where dimensions originate before introducing additional resizing logic. The goal is a chart that remains stable when the application behaves normally, not one that only works in a static example. Reliable responsiveness is the outcome of explicit layout design, measured behaviour and careful editorial choices.
Conclusion
Responsive Recharts design begins with a measurable parent container and continues with careful choices about label density, interaction and information priority. Test the graphic under changing layouts and imperfect data, not only at attractive demonstration sizes. A chart succeeds on every screen when its intended meaning remains legible and accessible.

