Skip to main content
Recharts provides powerful tools for creating responsive visualizations that adapt to different screen sizes and container dimensions. The ResponsiveContainer component is the foundation of responsive chart design.

ResponsiveContainer

The ResponsiveContainer component automatically adjusts chart dimensions based on its parent container size.

Basic usage

The parent container of ResponsiveContainer must have a defined width and height. ResponsiveContainer fills 100% of its parent by default.

How it works

The ResponsiveContainer component:
  1. Observes its parent container using the ResizeObserver API
  2. Calculates appropriate dimensions based on container size
  3. Provides these dimensions to child charts via React context
  4. Re-renders charts when container size changes

Container dimensions

Percentage dimensions

Use percentage values for fluid layouts:

Fixed dimensions

Use pixel values for fixed-size charts:

Mixed dimensions

Combine percentage and fixed values:

Aspect ratio

Maintain a specific width-to-height ratio:
When using aspect, the height is calculated as width / aspect. This is useful for maintaining visual consistency across different screen sizes.

Minimum and maximum dimensions

Set constraints on chart size:

Debouncing resize events

Optimize performance during rapid resize events:
Debouncing is useful when charts contain large datasets or complex rendering. It prevents excessive re-renders during window resizing.

Resize callback

Execute code when chart size changes:

Responsive patterns

Full-width charts

Dashboard grid

Mobile-first design

Breakpoint-based configuration

Container queries (CSS)

Leverage modern CSS container queries with ResponsiveContainer:

Performance considerations

Optimize large datasets

Lazy loading charts

Common issues

Ensure the parent container has explicit dimensions:
Add debounce to reduce re-renders:
Set minimum dimensions:
Adjust chart margins based on legend position: