Skip to content
nexubDesign System
v12.7.0

Getting Started

Strict CSP

Nexub DS works under a strict Content-Security-Policy with no 'unsafe-inline', hashes or nonces:

Terminal
default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'

@nexub/react injects no <style> tags of its own, and its CSS ships in @nexub/themes. A few components use Radix primitives that inject one when they open; the table says how to use those.

Components

Everything not listed here is CSP-safe as-is, including SettingsLayout, Popover, DatePicker, Combobox, Tooltip and Toast.

ComponentWhat happensUse it safely
Sheet / DrawerThe default scroll lock injects a <style> sized to the scrollbar, so no hash can allow it.Pass scrollLock="class" on Root. SettingsLayout does this for its phone menu.
DropdownMenu, ContextMenuIn the default modal mode, the scroll lock injects a <style>.Pass modal={false} on Root.
Dialog, AlertDialog, CommandPaletteThe default scroll lock injects a <style>.Pass scrollLock="class" on Root (7.2+). It becomes the default in 8.0.
SelectRadix always adds a scroll-lock <style>; without a nonce it's blocked (a console error, and the page behind can scroll).Pass your nonce to NexubProvider (below), or accept the console error.
ScrollArea, SelectRadix adds a fixed <style> that hides the native scrollbar. @nexub/themes/base ships the same rule, so it looks right; the blocked tag only logs a console error.Nothing to do. To silence the error, allow the hash the browser prints in it.
TSX
<Sheet.Root open={open} onOpenChange={setOpen} direction="left" scrollLock="class">
  <Sheet.Portal>
    <Sheet.Overlay />
    <Sheet.Content side="left">…</Sheet.Content>
  </Sheet.Portal>
</Sheet.Root>

scrollLock="class" adds nexub-scroll-lock (from @nexub/themes/base) to <html> while the overlay is shown. The sheet is still modal: focus stays inside, the rest of the page is hidden from screen readers, and Escape or a click outside closes it.

With a nonce

If your server sends a per-request nonce, give it to NexubProvider. Every<style> a Radix overlay injects then carries it, so all overlays work in their default modes under style-src-elem 'nonce-…' without 'unsafe-inline':

TSX
<NexubProvider nonce={nonce}>{children}</NexubProvider>

React style attributes are separate: allow them with style-src-attr 'unsafe-inline', which can't load or run anything.

Fonts

@nexub/themes/base bundles Plus Jakarta Sans. Every font file it references is over 8 KB, so Vite (4 KB limit) and webpack (8 KB) emit real files instead of data: URLs, and font-src 'self' works with default settings.

To make sure no font is ever inlined, including your own, add this to your Vite config:

TSX
// vite.config.ts
export default defineConfig({
  build: {
    // Never inline fonts as data: URLs (font-src 'self'); other assets keep the default.
    assetsInlineLimit: (file) => (/\.(woff2?|ttf|otf)$/.test(file) ? false : undefined),
  },
});

assetsInlineLimit: 0 also works but turns inlining off for every asset.

To use the system font instead, override the font token. Browsers only download a font a page uses, so the bundled one is never fetched:

CSS
:root {
  --font-family-sans: ui-sans-serif, system-ui, sans-serif;
}

Images

Vite inlines small images as data: URLs, which img-src 'self' data: allows. Serve @nexub/brand files from your own origin (see Using the brand assets).

Inline style attributes

Some components set positions and sizes through React's style prop. In the browser that goes through the CSSOM, which CSP allows. Server-rendered HTML is different: a style="…" attribute in the markup is blocked. Client-rendered apps (like a Vite SPA) aren't affected.

So components render scale values as classes, and server HTML has no style attribute for them. A test enforces this.

ComponentClasses (no style attribute)Inline style (blocked in server HTML)
Stack, Flex, GridNumeric gap on the spacing scale, common align/justify, cols/rows 1–12Arbitrary strings, e.g. gap="13px"
TextlineClamp 1–6lineClamp 7 and up
AspectRatio1, 16/9, 4/3, 3/2, 21/9, 9/16, 3/4, 2/3Any other ratio
SkeletonShape defaultsExplicit width/height
GradientDividerheight 1–4Thicker dividers
ProgressThe fill width is set through the CSSOM after hydration, so the bar fills in on load.
Fade, Collapse, Scale, SlideAnimate through inline style. Under strict CSP the first paint has no animation; later transitions work.

Radix sets a few internal styles of its own (Slider thumb position, the hidden form input behind Switch and Checkbox, the Popover anchor, Toast's screen-reader announcer).

Trusted Types

Nexub works with require-trusted-types-for 'script' enforced. The library never passes markup to innerHTML, never sets a script URL and never evaluates a string. One thing needs a rule: React writes the text of the <style> elements Radix injects (Select, ScrollArea) through innerHTML. That text is CSS with no tags in it, so a default policy that only lets tag-free strings through covers it without opening the sink:

JavaScript
// Before any other script. Header: trusted-types default; require-trusted-types-for 'script'
trustedTypes.createPolicy('default', {
  // Text with no "<" can't create an element. Markup is refused.
  createHTML: (s) => {
    if (!s.includes('<')) return s;
    throw new TypeError('markup refused');
  },
  // Your bundler's chunk loader, if it sets script.src (Turbopack does).
  createScriptURL: (u) => {
    const url = new URL(u, location.href);
    if (url.origin === location.origin && url.pathname.startsWith('/_next/static/')) return u;
    throw new TypeError('script URL refused');
  },
});

This site uses that policy, plus one allowed third-party script URL for its feedback form. With scrollLock="class" the overlays inject no style element at all.