Styling Overview

Styling Overview

XY has two rendering surfaces. Chart chrome—titles, axis labels, legends, tooltips, controls, and annotation labels—is DOM and participates in the normal CSS cascade. Data marks are painted by WebGL, SVG, or the native rasterizer, so XY compiles a deliberate CSS-property subset for them instead of claiming that arbitrary browser selectors can reach a canvas.

Solar panels
Inverters

Customize by part

Start with the visible part you want to change. Each link opens the exact section that owns it.

  • Fill, stroke, opacity, and gradients — area, line, point, bar, and column paint. Open section →
  • Axes, grid, and ticks — axis lines, horizontal guides, tick marks, and tick text. Open section →
  • Color scales and colorbars — continuous palettes, domains, ticks, and scale chrome. Open section →
  • Legend — content, placement, swatches, and DOM styling. Open section →
  • Tooltip — fields, formatting, placement, and container styling. Open section →
  • Annotations — rules, bands, arrows, markers, and callouts. Open section →
  • Interaction chrome — crosshair, selection, and toolbar controls. Open section →
  • Themes and Export — reusable palettes, dark mode, fonts, and output behavior. Open page →

Choose the styling surface

Start with the thing you want to change. DOM chrome can use classes or arbitrary safe DOM declarations; rendered geometry must use XY's validated mark or axis vocabulary.

MechanismSmall exampleBest for
Chart root classclass_name="rounded-xl border"Host layout, card chrome, and Tailwind utilities on one chart
Chart root stylestyle={"--brand": "#6e56cf"}Root CSS declarations and custom variables
Theme componentxy.theme(grid_color="#e2e8f0")Portable chart tokens shared by chrome and exports
Slot classesclass_names={"tooltip": "rounded-lg"}Tailwind utilities or existing classes on stable DOM slots
Slot stylesstyles={"title": {"font_size": 18}}Computed inline DOM styles on stable slots
Component-local stylexy.legend(class_name="text-xs")Keeping one legend, tooltip, colorbar, or modebar configuration self-contained
Mark stylexy.line(..., style={"stroke-width": 3})Cross-renderer paint for lines, points, areas, bars, and grids
Annotation stylexy.hline(5, style={"label_color": "red"})Annotation geometry and its DOM label
Export CSSchart.to_html(custom_css="...")Raw author CSS and attribute selectors in one browser export

If you are unsure, use this shortcut:

  • Styling a line, point, area, bar, or grid? Use its typed props or mark style=.
  • Styling a title, legend, tooltip, control, tick label, or annotation label? Use a slot class/style or the component's local class/style.
  • Styling the chart as a whole or defining reusable colors? Use chart class_name/style or xy.theme().
  • Styling only a self-contained HTML or Chromium export? Use custom_css.

What “your styles win” means

XY's built-in visual chrome rules live in the low-priority base cascade layer and use :where(...), which has zero CSS specificity. A later utility layer or ordinary unlayered author selector therefore overrides the default background, color, padding, border, font, shadow, or cursor without !important.

The promise is scoped to built-in visual defaults. XY still applies structural inline layout—position, size, z-index, and interaction state—and an explicit inline styles[slot] or per-annotation style naturally outranks a class. Marks follow their compiled style contract rather than the DOM cascade.

Styling troubleshooting

Start by identifying whether the thing you want to change is DOM chrome or a rendered mark. Inspect titles, legends, tooltips, controls, ticks, and labels as ordinary elements with data-xy-slot; style lines, areas, points, bars, and other canvas geometry through typed props or mark style=.

SymptomLikely causeFix
Tailwind classes are present but have no effectThe utility was not emitted by the host's Tailwind build, or the Tailwind plugin is missing.Enable Reflex's TailwindV4Plugin, keep fixed-chart classes literal, and continue to Customize Each Part.
A custom font silently falls backfont-family names a face the browser has not loaded.Register it in host CSS with @font-face, then apply the family to the chart root; see Custom fonts and export limitations.
A class changes the legend but not a line or pointMarks are WebGL/canvas geometry, not DOM nodes.Use the mark's typed paint props or supported style= declarations from Customize Each Part.
Standalone HTML looks different from the applicationThe exported document cannot inherit the host page's stylesheet or design-system variables.Put essential tokens on the chart and pass author rules with to_html(custom_css=...).
Native PNG ignores CSS or a custom fontThe native renderer does not run a browser cascade and uses XY's baked bitmap font.Use engine=Engine.chromium with custom_css when browser CSS/font fidelity is required.
Axis titles or annotation labels are clippedoverflow-hidden is applied to the XY root or a tight ancestor.Leave the chart root visible; apply intentional clipping to an outer wrapper and provide enough padding.
A responsive chart is blank or collapsedheight="100%" has no ancestor with a defined height, or the container initially measures zero.Give the chart/component an explicit height; width="100%" can remain fluid.
A class loses to another declarationInline styles, component-local styles, or later author rules win through the normal cascade.Remove the competing declaration or move the intended value to the same/higher-priority styling surface instead of adding !important.

For build, export, and adapter failures beyond styling, continue with the Troubleshooting guide.

The five styling destinations

  • Styling Overview (you are here) — identify the rendering surface and choose the right styling mechanism.
  • Examples — start from a polished, copyable chart or experiment with the interactive palette playground. Open Examples →
  • Customize Each Part — change marks, axes, grid, color scales, legends, tooltips, annotations, and interaction chrome. Open Customize Each Part →
  • Themes and Export — define reusable tokens, dark mode, fonts, and consistent HTML, SVG, or PNG output. Open Themes and Export →
  • Advanced Styling Gallery — inspect specialized renderer paths, uncertainty, density, facets, and export edge cases. Open Advanced Styling Gallery →
Built with Reflex