Graphite components can be customized at a high level through design tokens. This gives you control over theme colors and general styling. For more advanced customizations, you can make use of component variables to target individual components.
Graphite components are built with CSS custom properties (sometimes referred to as CSS variables) for easy customization of an application. CSS custom properties allow a value to be stored in one place, then referenced in multiple other places. They also make it possible to change CSS dynamically at runtime (which previously required a CSS preprocessor), useful for a dark theme for example. CSS custom properties make it easier than ever to override Graphite components to match a brand or theme.
Graphite makes use of several design tokens to provide a consistent appearance across components. You can customize them and use them in your own application with pure CSS — no preprocessor required.
Design tokens offer a high-level way to customize the Design System with minimal effort. There are no component-specific design tokens, however, as design tokens are intended to be generic and highly reusable. To customize an individual component, refer to the section entitled Component variables.
Design tokens are accessed through CSS custom properties that are defined in the
:root block of
core.css. This stylesheet is imported when you install Graphite components, so design tokens are available on your page at that point. Because design tokens are global, they're always prefixed with
--gr to avoid collisions with other libraries.
To customize a design token, simply override it in your stylesheet using a
/* Changes the primary color palette to purple */
--gr-color-primary-rgb: 168, 85, 247;
--gr-color-primary-contrast-rgb: 255, 255, 255;
/* Changes the font family */
--gr-font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Roboto', sans-serif;
Tip: you can use these tokens in your own custom components, to align them with the Graphite components. For example:
The Graphite Design System provides variables that exist at the component level, such as
--color. For a list of the custom properties a component accepts, view the "CSS custom properties" section of its API reference. For example, see the Button CSS custom properties.
/* Set the color on all gr-button elements */
* Set the background on a gr-button with a `fancy` class: