Plugins › Admin theme
Introduction
Build a system
Content
Using content
Plugins
Operations
Deploy
Recipes
Admin theme
Give the admin your or your client's look: a name, logo and color, a font, a favicon, and a
stylesheet of your own. Everything is in easy-cms.config.ts and works the same with Nuxt,
Next.js and the standalone server. The login page is themed too.
admin: {
brand: {
name: 'Acme Coffee',
logo: '/acme-logo.svg',
color: '#b45309',
favicon: '/favicon.svg',
font: {
family: 'IBM Plex Sans Thai',
stylesheet: 'https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;600&display=swap',
},
},
css: ['./admin/theme.css'],
},Name, logo and color
name shows in the menu, on the login page and in the browser tab, and logo (a path on your
site or an https:// URL) beside it. color is the main color as #rrggbb. Lighter and darker
shades come from it, and text on it turns dark when white would be hard to read. See
Branding the admin.
Font
brand.font.family comes before the admin's own fonts, so any letter it lacks (Thai, for a
font without Thai) is still drawn by them.
The admin's Content Security Policy allows fonts from the admin's own origin only. A font from elsewhere opens it for the origins you name, and no others:
| Option | |
|---|---|
family | Its font-family name, e.g. 'IBM Plex Sans Thai'. |
stylesheet | The CSS with its @font-face rules: an https:// URL or a path on your site. Its origin joins style-src. |
origins | Where the font files come from, for font-src, e.g. ['https://fonts.bunny.net']. For a Google Fonts stylesheet, https://fonts.gstatic.com is added by itself. |
From Bunny Fonts, which serves the CSS and the files from one origin:
font: {
family: 'Inter',
stylesheet: 'https://fonts.bunny.net/css?family=inter:400,600',
origins: ['https://fonts.bunny.net'],
},Font files on your own site need no CSP change. Leave stylesheet out, give only family, and
put the @font-face rules in admin.css, with paths on your site:
@font-face {
font-family: "Brand Sans";
src: url("/fonts/brand-sans.woff2") format("woff2");
font-weight: 100 900;
}The code font is --mono; set it in admin.css.
Favicon
brand.favicon is the browser tab's icon: a path on your site or an https:// URL, SVG, PNG or
ICO. Without one, the admin's icon is drawn in brand.color.
Your own stylesheet: admin.css
admin.css lists stylesheets loaded after the admin's own CSS, on every page and the login page.
Each is a file path relative to the project root or a package export, like
admin.modules. Remote URLs aren't allowed. The API serves them
(/api/cms/admin/ui/css/0.css…) with an ETag, so they need no change to the CSP. A file edited
while the server runs shows on the next page load.
Plugins can add stylesheets too. The config's own come after theirs, so yours win.
/* admin/theme.css */
:root {
--radius: 6px;
--radius-sm: 4px;
--font: "Brand Sans", var(--font-base);
}
[data-ecms="sidebar"] {
background: var(--surface-2);
}What is a contract
The admin's markup changes from release to release. Two things don't change without a note in
the changelog: the CSS variables and the data-ecms
hooks below. Write admin.css against these.
Other selectors
Class names, element order and other selectors work, but they aren't promised: any release may change them. A stylesheet that uses them may need fixing after an upgrade.
CSS variables
| Variable | |
|---|---|
--brand | The main color (brand.color). The accent shades derive from it. |
--accent, --accent-ink, --accent-soft | Buttons and links; text in the accent color; a light background of it. |
--bg, --surface, --surface-2 | The page, cards and panels, a quieter surface. |
--text, --text-muted, --faint | Text, less important text, the least. |
--border, --border-strong, --focus | Borders, stronger borders, the focus ring. |
--danger, --danger-soft | Errors and deleting. |
--ok, --success-soft | Success. |
--info, --info-soft | Information. |
--warning-text, --warning-soft | Warnings. |
--radius, --radius-sm | Corners of cards and dialogs, of buttons and inputs. |
--shadow, --shadow-sm | Shadows of dialogs and menus, of small things. |
--font, --font-base | The font, and the admin's own fonts (Thai included) to put after yours. |
--mono | The code font. |
Other variables, such as --kind-* (file types), --accent-hover and --accent-text, are the
admin's own.
Dark mode
The admin sets its dark colors in two places: when the user picks dark, and when they follow a system that is dark. Change dark colors in both:
:root[data-theme="dark"] {
--surface: #17171b;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--surface: #17171b;
}
}data-ecms hooks
| Hook | |
|---|---|
[data-ecms="app"] | The whole admin after login. |
[data-ecms="topbar"] | The bar at the top on small screens. |
[data-ecms="sidebar"] | The menu column. |
[data-ecms="nav"] | The menu's panel. |
[data-ecms="main"] | The page's content. data-ecms-view says which page: dashboard, list, create, edit, global, page (an admin page of your own). |
[data-ecms="page-header"] | The header of the dashboard, a list, an edit page, a global, the calendar and admin pages. |
[data-ecms="edit-sidebar"] | The side column of an edit page and a global. |
[data-ecms="edit-header"] | Your components beside Save (admin.edit.header). |
[data-ecms="edit-component"] | Your form in place of the admin's (admin.edit.component). |
[data-ecms="list-header"] | Your components above a list (admin.list.header). |
[data-ecms="list-layout"] | A layout of the list in place of the table (admin.list.layouts); data-layout is its name. |
[data-ecms="auth"] | The login page and the other pages before login. data-ecms-view: login, setup, forgot-password, reset-password. |
/* A quieter background behind lists, and a line under the header of edit pages. */
[data-ecms="main"][data-ecms-view="list"] {
background: var(--surface-2);
}
[data-ecms="main"][data-ecms-view="edit"] [data-ecms="page-header"] {
border-bottom: 1px solid var(--border);
}Your own components can go in the edit page's header and above a list: Admin components.
Tailwind CSS
admin.css is a plain CSS file, so a stylesheet built with Tailwind works. The admin's markup
isn't yours, so there are no classes to add to it: write rules with @apply on the hooks. Leave
out Tailwind's preflight, which would reset the whole admin:
/* admin/theme.src.css, built to admin/theme.css with the Tailwind CLI */
@layer theme, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/utilities.css" layer(utilities);
[data-ecms="page-header"] h1 {
@apply tracking-tight;
}Usually the CSS variables are less work. Tailwind in your own admin components
(easy-cms build:admin) is planned
(#549).