Theming Overview
RapiDoc renders inside a Shadow DOM, so your site’s CSS (resets, Tailwind, component libraries) can’t change it by accident, and its CSS can’t leak into your site. You style it on purpose, in three layers:
- Attributes for the common choices: theme, light or dark, corner radius, size. This page.
- CSS custom properties for any color, font or size: see Styling with CSS.
::part()selectors for individual elements: also on Styling with CSS.
Upgrading from RapiDoc v10?
RapiDoc v11 replaced styling attributes such as bg-color, text-color, header-color, regular-font and nav-* with CSS custom properties and ::part() selectors. (primary-color still works, as a shortcut for theme="#hex".) The v10 to v11 guide maps each one.
1. Attributes
Section titled “1. Attributes”Five attributes cover most visual changes. Try them:
A sketch: it shows only what these attributes change. The real element, with every setting, is on theThemes example.
Reference
Section titled “Reference”| Attribute | Allowed Values | Default | Description |
|---|---|---|---|
theme |
ember, carbon, cobalt, jade, indigo, amber, or any #hex code |
"amber" |
Brand color preset (dark and light palette), or a custom brand color hex code. |
color-scheme |
dark, light, system, auto |
"dark" |
Light or dark surfaces. system follows the operating system; auto follows the host page’s CSS color-scheme, else the operating system. |
radius |
none, sm, md, lg, full |
"sm" |
Corner radius scale applied across cards, buttons, badges, inputs, and modal dialogs. |
scale |
sm, default, lg |
"default" |
Proportional scale factor for UI base dimensions, body typography, code blocks, and sidebar width. |
2. Your brand color
Section titled “2. Your brand color”Pass a hex color as the theme:
<rapi-doc spec-url="https://api.example.com/openapi.json" theme="#2563eb" color-scheme="dark" radius="md"></rapi-doc>RapiDoc then:
- Primary Token: Sets
--primaryto your exact hex color. - Focus Ring: Sets
--ringto match the brand color. - Text on the color: Sets
--primary-foregroundto black for a light brand color or white for a dark one (by YIQ luminance), so button and badge labels stay readable.
3. Radius, scale and sidebar density
Section titled “3. Radius, scale and sidebar density”Corner Radius (radius)
Section titled “Corner Radius (radius)”The radius attribute controls roundness across the entire documentation interface:
radius="none": Sharp 0px corners for brutalist or dense terminal-style layouts.radius="sm"(default): Subtle 4px (0.25rem) radius for clean, modern interfaces.radius="md": Balanced 6px (0.375rem) radius matching contemporary web apps.radius="lg": Pronounced 8px (0.5rem) radius for playful, consumer-facing portals.radius="full": Pill-shaped buttons and inputs (9999px) with rounded 8px cards.
Scaling Factor (scale)
Section titled “Scaling Factor (scale)”The scale attribute controls typography, base sizing, and proportional margins:
scale="sm": Compact scale (13px base font, 17rem sidebar width). Ideal for embedded documentation cards or split-screen consoles.scale="default"(default): Standard desktop scale (14px base font, 18.75rem sidebar width). Optimal for full-page documentation portals.scale="lg": Generous scale (16px base font, 21rem sidebar width). Optimal for large monitors, accessibility compliance, and presentations.
Sidebar density
Section titled “Sidebar density”Each sidebar level has its own spacing: roomy rows for the API title, API Servers, Authentication and grouped tags, compact rows for operations. To change the operation rows’ padding, set --sidebar-item-padding (default 0.3125rem 0.625rem):
rapi-doc { --sidebar-item-padding: 0.5rem 0.625rem;}4. Fonts
Section titled “4. Fonts”RapiDoc does not download any fonts. Out of the box it uses the operating system’s own UI font: San Francisco on macOS and iOS, Segoe UI on Windows, Roboto on ChromeOS and Android. That means no font requests, no third-party calls, and it works offline and under a strict Content Security Policy.
To use your brand font, load it in your page and point two CSS variables at it:
--font-sans: body text, headings, and navigation links.--heading-fontfollows it unless you set that too.--font-mono: code blocks, HTTP methods, paths, and schemas.
Keep the system fonts at the end of the list, so text stays readable while your font loads or if it fails to load.
Declare @font-face in the page, not inside RapiDoc
Most browsers ignore @font-face rules inside a shadow root, so a font declared through css-file or in a <style> injected into RapiDoc never loads. Declare fonts in the page (a <style>, a stylesheet, or your app’s bundle). Fonts declared in the page are available inside RapiDoc’s Shadow DOM.
RapiDoc uses the weights 400, 500, 600, and 700. Load all four, or a single variable font that covers them, so the browser does not substitute the nearest weight or fake a bold.
Put the font files next to your site (for example in /fonts/) and declare them with @font-face. Nothing is requested from another server.
<head> <!-- Optional: start downloading the main font early --> <link rel="preload" href="/fonts/InterVariable.woff2" as="font" type="font/woff2" crossorigin />
<style> @font-face { font-family: 'Inter'; src: url('/fonts/InterVariable.woff2') format('woff2'); font-weight: 100 900; /* one variable file covers every weight */ font-style: normal; font-display: swap; } @font-face { font-family: 'JetBrains Mono'; src: url('/fonts/JetBrainsMono-Variable.woff2') format('woff2'); font-weight: 100 800; font-style: normal; font-display: swap; }
rapi-doc { --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace; } </style></head>
<body> <rapi-doc spec-url="https://rapidocui.com/specs/petstore.yaml" theme="jade"></rapi-doc></body>With a bundler (Vite, Astro, Next.js, webpack), Fontsource packages ship the font files and the @font-face rules. Your build copies the files into your site, so they are self-hosted too.
npm install @fontsource-variable/inter @fontsource-variable/jetbrains-mono// In your app's entry fileimport '@fontsource-variable/inter';import '@fontsource-variable/jetbrains-mono';import 'rapidoc';rapi-doc { --font-sans: 'Inter Variable', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --font-mono: 'JetBrains Mono Variable', ui-monospace, Menlo, Consolas, monospace;}The quickest setup, but every visitor’s browser contacts Google’s servers, which may need consent under privacy rules such as the GDPR, and your Content Security Policy must allow fonts.googleapis.com and fonts.gstatic.com.
<head> <link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet" />
<style> rapi-doc { --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace; } </style></head>If your site already loads its fonts and keeps them in CSS variables (Tailwind, shadcn/ui, a design system), reuse those variables:
rapi-doc { --font-sans: var(--font-inter, sans-serif); --font-mono: var(--font-jetbrains, monospace);}If your site names its variables --font-sans and --font-mono too, use inherit. Writing var(--font-sans) on rapi-doc would refer to itself.
rapi-doc { --font-sans: inherit; --font-mono: inherit;}See the Brand Fonts example to compare the system fonts with a brand font pairing.
5. Changing the theme at runtime
Section titled “5. Changing the theme at runtime”All these attributes can be changed at any time, for example from your site’s own theme switcher:
const doc = document.querySelector('rapi-doc');
// Switch brand preset or custom hex colorfunction setBrandColor(themeValue) { doc.setAttribute('theme', themeValue); // e.g., 'jade' or '#2563eb'}
// Toggle between dark and light modesfunction toggleDarkMode() { const current = doc.getAttribute('color-scheme') || 'dark'; doc.setAttribute('color-scheme', current === 'dark' ? 'light' : 'dark');}
// Adjust corner radius dynamicallyfunction updateRadius(radiusValue) { doc.setAttribute('radius', radiusValue); // 'none', 'sm', 'md', 'lg', 'full'}
// Make everything smaller or largerfunction setScale(size) { doc.setAttribute('scale', size); // 'sm', 'default', 'lg'}