Styling
Customize colors, fonts and color mode.
Your stylesheet is src/theme.css. Without one, the site uses the neutral color preset. With one, the site uses only what the file imports, so start it with a preset:
@import "vuesho/style/ocean.css";Color Presets
Each preset has colors for light and dark mode:
Neutral Default
vuesho/style/neutral.cssBlack
vuesho/style/black.cssVitePress
vuesho/style/vitepress.cssDusk
vuesho/style/dusk.cssCatppuccin
vuesho/style/catppuccin.cssOcean
vuesho/style/ocean.cssPurple
vuesho/style/purple.cssSolar
vuesho/style/solar.cssEmerald
vuesho/style/emerald.cssRuby
vuesho/style/ruby.cssAspen
vuesho/style/aspen.cssshadcn/ui
vuesho/style/shadcn.css
The shadcn preset reads shadcn/ui's CSS variables, like --primary and --border, so the docs match an app built with it.
Colors
The colors are CSS variables named --color-fd-<name>. Set them after the preset's import, in :root for light mode and in .dark for dark mode:
@import "vuesho/style/neutral.css";
:root {
--color-fd-primary: hsl(160, 84%, 39%);
}
.dark {
--color-fd-primary: hsl(158, 64%, 52%);
}Most colors come in pairs: --color-fd-primary is a primary button's background, and --color-fd-primary-foreground is its text color.
| Name | Where the UI uses it |
|---|---|
background | The page, with its text in foreground |
primary | Links, the active sidebar item, primary buttons |
muted | Subtle surfaces and secondary text |
card | Cards, code blocks and the sidebar |
popover | Popovers, menus and dialogs |
secondary | Secondary controls, like the search button |
accent | Hovered items, like the sidebar's links |
border, ring | Borders, and outlines of focused elements |
Color Mode
Readers switch between light and dark mode with the button in the sidebar or the navbar, or with the D key, and their choice is saved in the browser. Configure the color mode with ui.colorMode in the config:
createSite(docs.toSource()).config({
ui: {
colorMode: {
// The color mode before the reader picks one: "system" (default), "light" or "dark"
default: "dark",
// The key that switches the color mode, or `false` for none
hotKey: "t",
// The `localStorage` key for the reader's choice
storageKey: "acme-color-mode",
},
},
});fixed: true keeps every page in the default color mode and hides the button:
createSite(docs.toSource()).config({
ui: { colorMode: { default: "dark", fixed: true } },
});In a component, read or set the color mode with useColorMode(). When hotKey is false, your component can bind another shortcut, like Shift+D.
An inline script sets the color mode before the first paint, so a strict Content Security Policy must allow that script.
Color Mode per Page
colorMode in the page data keeps one page in a color mode. In a custom page, set it with definePage():
<script setup lang="ts">
import { definePage } from "vuesho/client";
definePage({ data: { title: "Acme", colorMode: "dark" } });
</script>For a Markdown page, return colorMode from a plugin's transformPage hook, which changes the page data:
createSite(docs.toSource()).plugins(recommendedPreset(), {
name: "dark-showcase",
transformPage: (_data, { path }) => (path === "/showcase" ? { colorMode: "dark" } : undefined),
});Fonts
The UI uses --font-sans for text and --font-mono for code. Install a font from Fontsource, and Vite bundles its files with the site:
npm i @fontsource-variable/geist@import "vuesho/style/neutral.css";
@import "@fontsource-variable/geist";
:root {
--font-sans: "Geist Variable", sans-serif;
}Font Files
To load a font file from your project, use @font-face with a relative URL, and Vite bundles the file:
@import "vuesho/style/neutral.css";
@font-face {
font-family: "Inter";
src: url("./fonts/Inter.woff2") format("woff2");
font-weight: 100 900;
font-display: swap;
}
:root {
--font-sans: "Inter", sans-serif;
}Preloading Fonts
To render text in your font from the first paint, preload the font file with a head tag in the theme. ?url imports the file's URL:
import { defineTheme } from "vuesho/theme";
import defaultTheme from "vuesho/theme/default";
import geist from "@fontsource-variable/geist/files/geist-latin-wght-normal.woff2?url";
export default defineTheme({
extends: defaultTheme,
head: [
{
tag: "link",
attrs: { rel: "preload", href: geist, as: "font", type: "font/woff2", crossorigin: "" },
},
],
});Fallback Fonts
fontaine generates a fallback system font with your font's metrics, so the layout doesn't shift once the font loads:
npm i -D fontaineimport { FontaineTransform } from "fontaine";
import { defineConfig } from "vite";
import vuesho from "vuesho/vite";
export default defineConfig({
plugins: [vuesho(), FontaineTransform.vite({ fallbacks: ["Arial"] })],
});fontaine doesn't read CSS variables, so add the fallback font, named <font name> fallback, to --font-sans:
:root {
--font-sans: "Geist Variable", "Geist Variable fallback", sans-serif;
}Tailwind CSS
The stylesheet compiles with Tailwind CSS, so a Tailwind class works in any file of your site, like a custom page, a component or a Markdown page, with no setup:
<template>
<main class="mx-auto grid max-w-5xl gap-6 md:grid-cols-2">...</main>
</template>In src/theme.css, use the directives of Tailwind CSS, like @theme for a color that your classes use:
@import "vuesho/style/ocean.css";
@theme {
--color-brand: hsl(160, 84%, 39%); /* bg-brand, text-brand */
}Tailwind CSS detects classes in your project's files, except those that .gitignore lists, and in the modules of Vuesho and its plugins. Add a class that none of those files has with @source inline(), like one that a markdown-it plugin from npm writes, and leave out a folder that holds no UI with @source not:
@source inline("bg-red-500 bg-green-500");
@source not "../public/registry";To pass options to Tailwind CSS, like important, import it yourself, then the colors of a preset from vuesho/css and the stylesheet of the UI:
@import "tailwindcss" important;
@import "vuesho/css/ocean.css";
@import "vuesho/style/ui.css";Layout Width
--fd-layout-width sets the maximum width of the docs and notebook layouts, 97rem by default. The home layout is always 1400px wide, and the other layouts ignore the variable:
:root {
--fd-layout-width: 80rem;
}Utility Classes
These classes style your components like the UI:
prosestyles HTML like a Markdown page.prose-smandprose-xsmake prose smaller.prose-no-marginremoves the margins at the start and the end.fd-stepson a container andfd-stepon each child number the children, like the Steps component.
<template>
<div class="prose prose-sm">
<slot />
</div>
</template>