Recharts provides a z-index system for controlling the layering of chart elements. Since SVG doesn’t support CSSDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/recharts/recharts/llms.txt
Use this file to discover all available pages before exploring further.
z-index, Recharts uses portals to render elements in the correct order.
ZIndexLayer
A component that renders its children into a portal corresponding to the given z-index.Numeric z-index value. Higher values render on top of lower values.
If
undefined or 0, content renders in the default layer without portals.The content to render inside this z-index layer.
Usage
TheZIndexLayer component must be used inside a chart component:
ZIndexable
Interface for components that support thezIndex prop.
Components with zIndex support
Many Recharts components accept azIndex prop:
DefaultZIndexes
A collection of all default z-index values used by Recharts. You can reuse these or define your own.Default z-index layers
Background layers (negative z-index)
CartesianGrid and PolarGrid
Background of Bar and RadialBar. Not visible by default but can be enabled with
background={true}.Default layer
Elements without a specificzIndex prop render at zIndex: 0 (the default layer).
Chart elements (positive z-index)
Area, Pie, Radar, and ReferenceArea
Cursor rectangle in bar charts. Renders below bars so it doesn’t hide other bars in stacked charts.
Bar and RadialBar
Line, ReferenceLine, and ErrorBar
XAxis, YAxis, PolarAngleAxis, and PolarRadiusAxis (ticks, lines, and children)
Scatter, ReferenceDot, and dots on Line/Area/Radar when
dot={true}Interactive layers (high z-index)
Highlight rectangle when hovering over a Bar or RadialBar
Cursor line in Line, Area, Scatter, and Radar charts. Also applies to radial cursor in RadialBarChart.
Highlight dot when hovering over a point in Line, Area, Scatter, or Radar
LabelList and Label components, including axis labels
Example usage
Z-Index guide
For a comprehensive guide on using z-index in Recharts, see the Z-Index and layers guide.How it works
-
Portal-based rendering: Since SVG doesn’t support CSS
z-index, Recharts creates separate SVG<g>elements for each z-index layer. -
Dynamic registration: Z-index layers are registered dynamically. When you use a
zIndexprop orZIndexLayer, Recharts creates the corresponding portal automatically. -
Rendering order: SVG elements are rendered in the order they appear in the DOM. Recharts organizes layers from lowest to highest z-index:
- Negative z-index layers (e.g., grid at -100)
- Default layer (z-index 0)
- Positive z-index layers (e.g., labels at 2000)
- No performance overhead: If you don’t use z-index features, there’s no performance impact. Portals are only created for the z-index values you actually use.