Skip to main content
Recharts provides a z-index system for controlling the layering of chart elements. Since SVG doesn’t support CSS 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.
number | undefined
Numeric z-index value. Higher values render on top of lower values. If undefined or 0, content renders in the default layer without portals.
ReactNode
The content to render inside this z-index layer.
Since: 3.4

Usage

The ZIndexLayer component must be used inside a chart component:

ZIndexable

Interface for components that support the zIndex prop.
Since: 3.4

Components with zIndex support

Many Recharts components accept a zIndex 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)

-100
CartesianGrid and PolarGrid
-50
Background of Bar and RadialBar. Not visible by default but can be enabled with background={true}.

Default layer

Elements without a specific zIndex prop render at zIndex: 0 (the default layer).

Chart elements (positive z-index)

100
Area, Pie, Radar, and ReferenceArea
200
Cursor rectangle in bar charts. Renders below bars so it doesn’t hide other bars in stacked charts.
300
Bar and RadialBar
400
Line, ReferenceLine, and ErrorBar
500
XAxis, YAxis, PolarAngleAxis, and PolarRadiusAxis (ticks, lines, and children)
600
Scatter, ReferenceDot, and dots on Line/Area/Radar when dot={true}

Interactive layers (high z-index)

1000
Highlight rectangle when hovering over a Bar or RadialBar
1100
Cursor line in Line, Area, Scatter, and Radar charts. Also applies to radial cursor in RadialBarChart.
1200
Highlight dot when hovering over a point in Line, Area, Scatter, or Radar
2000
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

  1. Portal-based rendering: Since SVG doesn’t support CSS z-index, Recharts creates separate SVG <g> elements for each z-index layer.
  2. Dynamic registration: Z-index layers are registered dynamically. When you use a zIndex prop or ZIndexLayer, Recharts creates the corresponding portal automatically.
  3. 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)
  4. 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.

TypeScript

Full type definitions are available: