Theming Utilities from @backstage/theme
Backstage provides a powerful theming API via the @backstage/theme package. The key exports include:
| Export | Purpose |
|---|---|
createBaseThemeOptions | Builds a base set of theme options (palette, typography, and page settings). |
createUnifiedTheme | Combines base options into a full theme object consumable by the ThemeProvider. |
palettes | Collection of predefined light and dark color palettes. |
Make sure
@backstage/theme is installed in your workspace. If not, run yarn add @backstage/theme or npm install @backstage/theme.1. Defining a Custom Theme
Follow these steps to create a new theme file:- Navigate to
packages/app/srcin your Backstage project. - Create a
themefolder if it doesn’t already exist. - Inside
theme, add a file namedmy-theme.ts:
- Spreads the light palette from
palettes.light. - Overrides the default
fontFamilyto'Comic Sans MS'. - Sets
defaultPageThemeto'home'.
Comic Sans MS is used here as an example. Choose fonts that align with your brand guidelines.
2. Applying Your Custom Theme in App.tsx
To register and activate your new theme, update the createApp call in packages/app/src/App.tsx:
- id: A unique identifier (e.g.,
my-theme). - title: Display name in the UI theme selector.
- variant: Choose
'light'or'dark'. - icon: React element shown next to the theme name.
- Provider: Wraps the application in
<UnifiedThemeProvider theme={myTheme}>.
Backstage will hot-reload your theme changes—no need to restart your development server.
3. Creating a More Colorful “Fun” Theme
You can further customize palette attributes (primary, secondary, navigation) as shown:funTheme in your App.tsx:
Preview of Custom Theme
Upon refreshing the UI, your custom colors are applied across Backstage: