Skip to Content
Vuesho

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:

src/theme.css
@import "vuesho/style/ocean.css";

Color Presets

Each preset has colors for light and dark mode:

  • Neutral Default

    vuesho/style/neutral.css
  • Black

    vuesho/style/black.css
  • VitePress

    vuesho/style/vitepress.css
  • Dusk

    vuesho/style/dusk.css
  • Catppuccin

    vuesho/style/catppuccin.css
  • Ocean

    vuesho/style/ocean.css
  • Purple

    vuesho/style/purple.css
  • Solar

    vuesho/style/solar.css
  • Emerald

    vuesho/style/emerald.css
  • Ruby

    vuesho/style/ruby.css
  • Aspen

    vuesho/style/aspen.css
  • shadcn/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:

src/theme.css
@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.

NameWhere the UI uses it
backgroundThe page, with its text in foreground
primaryLinks, the active sidebar item, primary buttons
mutedSubtle surfaces and secondary text
cardCards, code blocks and the sidebar
popoverPopovers, menus and dialogs
secondarySecondary controls, like the search button
accentHovered items, like the sidebar's links
border, ringBorders, 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:

vuesho.config.ts
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:

vuesho.config.ts
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():

src/pages/index.vue
<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:

vuesho.config.ts
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
src/theme.css
@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:

src/theme.css
@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:

src/theme.ts
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 fontaine
vite.config.ts
import { 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:

src/theme.css
: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:

src/pages/index.vue
<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:

src/theme.css
@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:

src/theme.css
@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:

src/theme.css
@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:

src/theme.css
:root {
  --fd-layout-width: 80rem;
}

Utility Classes

These classes style your components like the UI:

  • prose styles HTML like a Markdown page.
  • prose-sm and prose-xs make prose smaller.
  • prose-no-margin removes the margins at the start and the end.
  • fd-steps on a container and fd-step on each child number the children, like the Steps component.
src/components/Note.vue
<template>
  <div class="prose prose-sm">
    <slot />
  </div>
</template>