Theming
Change how the admin panel looks with a theme, and add your own stylesheets and scripts
Introduction
The admin panel is built with the StellarAdmin.UI components, and uses the same themes. A theme is a CSS file that sets the theme variables, such as the colors, fonts and corner radius. Without one, the admin panel uses the default theme.
To use a theme, save its file in your app's wwwroot folder, and add it with AddStylesheet():
builder.Services.AddStellarAdmin(admin =>
{
admin.AddStylesheet("~/css/theme.css");
});StellarAdmin loads your stylesheets after its own, in the order you add them, so the theme's variables replace the default ones.
Making a theme
You can create your own theme in any of these ways:
- Start from a preset in the theme builder, change it, and download the file.
- Ask your coding agent to make one, with the stellar-admin-theme skill.
- Write one by hand from the theme variables.
A theme has a light and a dark variant. See dark mode.
Adding fonts
When the theme uses a web font, add the font's stylesheet before the theme. The example below loads Lexend from Google Fonts:
builder.Services.AddStellarAdmin(admin =>
{
admin.AddStylesheet("https://fonts.googleapis.com/css2?family=Lexend:wght@400..700&display=swap");
admin.AddStylesheet("~/css/theme.css");
});See adding fonts for how a theme sets its fonts.
Adding your own stylesheets and scripts
StellarAdmin's stylesheet only has the classes its own components use. To use other classes, such as Tailwind classes, in your custom pages or custom editors, add a stylesheet and reference it with AddStylesheet().
To add a script to every page of the admin panel, call AddScript():
admin.AddScript("~/js/admin.js");StellarAdmin loads your scripts with defer, after its own, in the order you add them.
Pass AddStylesheet() and AddScript() an absolute URL, or a path in your app that starts with ~/. Adding the same path twice adds it once.