A theme from one color
This tool builds a Material 3 color scheme from one seed color. It uses Google's
material-color-utilities library, version 0.4.0, in your browser.
The library works in a color space called HCT: Hue, Chroma and Tone.
Hue is the color family, in degrees. Chroma is colorfulness. Tone is the CIELAB lightness L*, from 0 (black) to 100 (white). The library uses L* because it is linear to human perception. This links tone to contrast: a difference of 40 in tone guarantees a contrast ratio of at least 3.0.
From the seed, the library builds six tonal palettes:
- Primary: the seed's hue, chroma at least 48.
- Secondary: the seed's hue, chroma 16.
- Tertiary: the seed's hue plus 60 degrees, chroma 24.
- Neutral: the seed's hue, chroma 4.
- Neutral variant: the seed's hue, chroma 8.
- Error: hue 25, chroma 84. This palette does not depend on the seed.
The tool reads 13 tones from each palette: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90,
95, 99 and 100. Each color role is one tone of one palette. In the light scheme,
primary is Primary tone 40, onPrimary is tone 100,
primaryContainer is tone 90 and onPrimaryContainer is
tone 10. In the dark scheme the same four roles are tones 80, 20, 30 and 90.
Secondary, Tertiary and Error follow the same pattern. surface is
Neutral tone 99 in light and tone 10 in dark.
These role-to-tone values come from the library's Scheme class. The
library marks Scheme as deprecated and recommends
DynamicScheme for new code.
What the role names mean
primary is the color shown most often across your app. Android's
Compose docs list prominent buttons, active states and the tint of elevated
surfaces as uses. secondary is for less prominent components, such as
filter chips. tertiary is a contrasting accent that balances primary
and secondary or draws attention to an element.
Each of these has an "on" role for text and icons placed on top of it, and a
container pair. Use onPrimary on primary and
onPrimaryContainer on primaryContainer. The same rule
applies to secondary, tertiary, error and the neutral roles. Mixing roles from
different pairs can give poor contrast.
The other roles, as the Compose ColorScheme reference describes them:
surface: the surface of components such as cards, sheets and menus.surfaceVariantandonSurfaceVariant: variants with less emphasis.background: the color behind scrollable content.outline: a subtle color for boundaries.outlineVariantis for decorative boundaries where strong contrast is not needed.inverseSurface,inverseOnSurfaceandinversePrimary: for places that need the inverse scheme, such as a Snackbar and its button.scrim: a color that obscures content.surfaceTint: applied on top of the surface by components that use tonal elevation.
Dropping the output into your project
The Kotlin output contains two schemes, LightColors and
DarkColors, and a MyAppTheme composable that picks one
with isSystemInDarkTheme() and passes it to
MaterialTheme. Paste it into your theme file and rename the
composable to match your app. Then wrap your content in it:
setContent {
MyAppTheme {
// Your composables here
}
}
In your composables, read colors from the theme, for example
MaterialTheme.colorScheme.primary. A hard-coded
Color(0xFF6750A4) does not change between the light and dark schemes.
If you're coming from Material 2
Android's migration guide says there is no reasonable direct mapping from M2
Colors to the M3 ColorScheme. It recommends generating a
new scheme from your M2 colors, with this starting point: M2
primary as the Primary source, primaryVariant as
Secondary, secondary as Tertiary, and surface or
background as Neutral. Roles with the same name in M2 and M3 may end
up with different hex values.
ContentAlpha and LocalContentAlpha do not exist in M3.
Where M2 used onSurface with ContentAlpha.medium, M3 uses
onSurfaceVariant. For disabled content, M3 uses
onSurface.copy(alpha = 0.38f).
M3 has two kinds of elevation. Shadow elevation casts a shadow, as in M2. Tonal
elevation overlays a color. The M3 Surface takes both
shadowElevation and tonalElevation. The tonal overlay uses
primary by default. You can change it with the
surfaceTint role.
Things to watch
The Primary palette always gets a chroma of at least 48, whatever the seed's chroma. A pale seed therefore produces a more colorful Primary palette than the seed itself.
Editing single colors by hand removes the tone distance between a role and its "on" role. If you change a color, check the contrast again. The token view in this tool shows a contrast ratio for each pair.
For a custom brand color that is not part of the scheme, such as a warning yellow,
material-color-utilities has Blend.harmonize. It rotates
the color's hue toward the seed's hue by half the difference, at most 15 degrees.
What this tool doesn't generate
The output covers 29 roles. Compose Material 3 1.2.0 added the surface container
roles (surfaceContainerLowest through
surfaceContainerHighest, plus surfaceBright and
surfaceDim). Since Compose Material 3 1.3.0, components that used
Surface with tonal elevation use these roles by default. The tool does
not emit them. Any role you do not pass to lightColorScheme() or
darkColorScheme() keeps the library's baseline default value.
The tool also does not produce dynamic color. Dynamic color derives the scheme from
the user's wallpaper and is available on Android 12 (API 31) and higher. Call
dynamicLightColorScheme(context) or
dynamicDarkColorScheme(context) when
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S, and use this tool's
output as the fallback on older versions.