Styles and UI Libraries
Your fields, pages and admin bar items render inside the admin, next to its own interface. This page shows how to style them without changing the rest of the admin, and what to expect when you write them with Vue or React: which parts of your app they can use, and what they add to the download.
Where your code renders
The admin runs on a page of its own, at /admin. It is not a page of your app:
- Your site's CSS does not load there, and your app does not run there. In Nuxt, there is no Nuxt app on the admin page.
- Fields and pages render in the admin's DOM, so the admin's CSS reaches them.
- Admin bar items render on your site, inside a shadow root. Neither your site's CSS nor the admin's reaches them.
Style fields and pages
Your markup starts from the admin's CSS reset: headings have no size, lists have no bullets and buttons have no look. Style it in one of these ways.
Use the admin's classes
The admin shares three classes that look like its own controls:
| Class | Looks like |
|---|---|
.input | A text input |
.btn | A primary button |
.btn-ghost | A button without a background |
<input class="input" placeholder="Search" /> <button class="btn" type="button">Save</button>
Do not rely on other classes of the admin, like flex or p-4. The admin only ships the utilities it uses itself, and that list changes between versions.
Bring your own CSS
A .client.ts module or a Vue component MAY import CSS. The admin loads it into its page when your field or page first mounts.
That CSS applies to the whole admin, so scope every selector. Give your page a class, or use Vue's <style scoped>:
.stats {
display: grid;
gap: 1rem;
}
.stats h2 {
font-size: 1.25rem;
font-weight: 600;
}
import type { Mount, PageContext } from "tenoncms/admin";
import "./stats.css";
export const mountStats: Mount<PageContext> = (el) => {
el.classList.add("stats");
el.innerHTML = "<h2>Stats</h2>";
return () => el.replaceChildren();
};
h2 { … } or button { … }, restyles the admin too.Use Tailwind
If your project uses Tailwind 4, compile your own utilities with a prefix, and leave out Tailwind's reset:
@import "tailwindcss/theme" layer(theme) prefix(tw);
@import "tailwindcss/utilities" layer(utilities) source(none);
@source "./";
Import the file in your module, and write the classes with the prefix, like tw:flex tw:gap-2. The prefix keeps your classes apart from the admin's. Without preflight, the admin keeps its own reset.
Light and dark
Editors switch the admin between light and dark. In dark mode, <html> has the class dark. Neutral colors with transparency, like rgb(128 128 128 / 0.15), work in both.
var(--foreground) and var(--border). They follow the theme, but they are not a public API yet and can change between versions.Style admin bar items
The admin bar sits in a shadow root on your site, so CSS from files does not reach it. Its modules MUST NOT import CSS: the bar loads on every page, and the build rejects CSS in its modules.
Style a bar item inline, or import CSS as a string with ?inline and add it inside the item:
import type { AdminBarItemContext, Mount } from "tenoncms/admin";
import css from "./bar.css?inline";
export const mountBadge: Mount<AdminBarItemContext> = (el) => {
const style = Object.assign(document.createElement("style"), { textContent: css });
const badge = Object.assign(document.createElement("span"), {
className: "badge",
textContent: "New",
});
el.append(style, badge);
return () => el.replaceChildren();
};
Keep bar code in its own module, away from styled fields and pages.
Vue, React and your framework
renderVue() and renderReact() run your components with the vue or react-dom of your project. Your build compiles them:
| Framework | For Vue components | For React components |
|---|---|---|
| Nuxt | Works | Add @vitejs/plugin-react |
| Astro | Add @astrojs/vue | Add @astrojs/react |
| TanStack Start | Add @vitejs/plugin-vue | Works |
Two copies of Vue
The admin is a Vue app with its own copy of Vue. Your Vue components use your copy. On the admin page, both run side by side:
- They share nothing, so their versions can differ.
- Your components cannot use the admin's components. Use its classes for the look.
- Nuxt composables and components, like
useFetch(),useState()or<NuxtLink>, need the Nuxt app. The admin page has none. Import fromvuedirectly, and read data withloadorcreateClient(). - Use a plain
<a>in place of<NuxtLink>. A link undertenon.baseopens in the admin without a reload.
One app per mount
renderVue() creates a new Vue app for each field or page, inside <Suspense>, so await works at the top of <script setup>. React gets a new root for each.
- Each app is on its own. Two custom fields on one form do not share a store. State in a module, outside the component, is shared.
renderVue()installs no plugins. For Pinia, vue-i18n or another plugin, write themountyourself:
import { createPinia } from "pinia";
import { createApp, h, reactive } from "vue";
import type { Mount, PageContext } from "tenoncms/admin";
import Stats from "./Stats.vue";
export const mountStats: Mount<PageContext> = (el, ctx) => {
const props = reactive({ ...ctx });
const app = createApp({ render: () => h(Stats, props) });
app.use(createPinia());
app.mount(el);
return { update: (next) => Object.assign(props, next), unmount: () => app.unmount() };
};
In React, wrap your component in its providers instead, like a QueryClientProvider.
What visitors download
Nothing. Your admin code does not reach your site's pages:
- The admin is a second entry in your build, served on its own page. Your site's pages never load it.
- Each
.client.tsmodule is its own chunk. The admin loads it when it is first needed, like when a form with your field opens. - React or a second Vue loads on the admin page only, the first time one of your components mounts. A Nuxt site can use React in the admin without sending React to visitors.
- The admin bar loads only for signed-in editors. Its items load with it.
Your admin code adds to the build and to the files you deploy, not to the pages of your site.
Related resources
- Custom fields: browser code and the
mountfunction. - Custom pages and actions: your own views in the admin.
- Admin: the admin bar and its items.