Skip to content

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:

  1. Attributes for the common choices: theme, light or dark, corner radius, size. This page.
  2. CSS custom properties for any color, font or size: see Styling with CSS.
  3. ::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.


Five attributes cover most visual changes. Try them:

Theme
Color scheme
Radius
Scale
index.html

A sketch: it shows only what these attributes change. The real element, with every setting, is on theThemes example.

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.

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:

  1. Primary Token: Sets --primary to your exact hex color.
  2. Focus Ring: Sets --ring to match the brand color.
  3. Text on the color: Sets --primary-foreground to black for a light brand color or white for a dark one (by YIQ luminance), so button and badge labels stay readable.

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.

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.

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;
}

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-font follows 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>

See the Brand Fonts example to compare the system fonts with a brand font pairing.


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 color
function setBrandColor(themeValue) {
doc.setAttribute('theme', themeValue); // e.g., 'jade' or '#2563eb'
}
// Toggle between dark and light modes
function toggleDarkMode() {
const current = doc.getAttribute('color-scheme') || 'dark';
doc.setAttribute('color-scheme', current === 'dark' ? 'light' : 'dark');
}
// Adjust corner radius dynamically
function updateRadius(radiusValue) {
doc.setAttribute('radius', radiusValue); // 'none', 'sm', 'md', 'lg', 'full'
}
// Make everything smaller or larger
function setScale(size) {
doc.setAttribute('scale', size); // 'sm', 'default', 'lg'
}