Customize a Design
This guide addresses how to customize a design system with CSS variables.
:::{versionadded} 1.0.0 The design feature was added in 1.0.0 and is actively being developed and improved. Currently there are a limited number of design variables but in future the goal is to expose a large variety of styling options via CSS variables. :::
The Design systems in Panel are set up to be overridden by CSS variables. The usual order of fallbacks for CSS variables is the following:
User defined design variables (e.g.
--design-primary-color
)Editor/notebook dependent variables (e.g.
--jp-brand-color0
, for JupyterLab)The theme CSS variable definitions (e.g.
--panel-primary-color
)
To override a particular style we therefore simply have to override one of the user defined design variables:
Variable | Description |
---|---|
--design-primary-color | Primary color of the design. |
--design-primary-text-color | Color of text rendered on top of primary color. |
--design-secondary-color | Secondary color of the design. |
--design-secondary-text-color | Color of text rendered on top of secondary color. |
--design-background-color | Color of the background layer. |
--design-background-text-color | Color of text rendered on top of the background layer. |
--design-surface-color | Color of the surface layer. |
--design-surface-text-color | Color of text rendered on top of the surface layer. |
When and how to set these variables depends on the precise use case, e.g. if you consistently want to override the colors in a template, use the Template.config.raw_css
or Template.config.css_files
parameters to define an inline or imported stylesheet that will apply across the entire template.
For global overrides that apply in all scenarios you can use the pn.config.global_css
parameter, e.g. here we initialize it via the pn.extension
:
When defining design variable overrides globally use the :root
CSS selector, which applies the variable from the root on down.
Alternatively you can also define it directly on a component by adding it to the stylesheets
and prefixing it with the :host
selector: