Style the components
Outcome: the SDK’s form and views look the same on any page, and your page keeps its own fonts, colors and resets.
You need: an <AnvilProvider> around the components, as in
Add a LOC form.
Import the stylesheet once
Add one import to your app’s main CSS file:
@import '@anvilresearchlabs/sdk/styles.css';It carries everything the components need: their tokens, their utilities and their own reset. Your page needs no Tailwind, no CSS reset and no Anvil design-token setup.
What the stylesheet touches
- Each component’s outer element. Every component marks its own outermost element, the one its
classNamelands on, withdata-anvil-root. The stylesheet styles that element and what is inside it. It adds no wrapper element. - Portaled content. Popovers, menus, selects and dialogs open into one
data-anvil-rootelement at the end of<body>, so they escape youroverflowandtransformcontainers and are styled the same way. The first component to mount adds it and the last one to unmount removes it. It is positioned out of the page flow, so it takes no space in your layout, even when<body>is a flex or grid container. - Its own reset. On those elements the components get
box-sizing: border-box, controls that inherit the font, and no browser margins, padding, fieldset borders or list markers.
Everything else on your page keeps its own styles: your body background and text color, your
button and fieldset rules, the headings and copy you place next to a component, and, in light
mode, your page’s color-scheme. <AnvilProvider> and the hooks add no element to the page.
Set the font
Each component sets one font on its outer element, and everything inside inherits it. Set
--anvil-font-sans to the font stack your page uses:
:root { --anvil-font-sans: 'Your Brand Sans', system-ui, sans-serif;}Without it, the components use the platform’s UI font (system-ui, then common sans-serif
fallbacks). Numbers and addresses use the SDK’s monospace data face.
Lay out with className
A component’s className lands on its outer element. Use it for placement with your own CSS: width,
margins, grid or flex position. Your rules that are not in a cascade layer win over the stylesheet’s
reset on that element. The stylesheet styles everything inside the component, and its internal class
names can change between releases.
<CreateLOCFlow createOnly className="checkout-loc-form" />.checkout-loc-form { max-width: 36rem; margin-inline: auto;}Dark mode
The components switch to their dark colors when an ancestor element, usually <html>, has the
dark class.
What the SDK handles, and what your app handles
- The SDK styles its components and their popups, and resets them, from each component’s outer element inward.
- Your app imports the stylesheet once, renders the components inside
<AnvilProvider>, sets--anvil-font-sansif it wants its own font, and adds thedarkclass for dark mode.
Good to know
- The stylesheet still declares its design tokens as custom properties on
:root. A page that defines custom properties with the same names (--radius,--border,--ring,--spacing, or shadcn’s color names) can change how the components look. - Rules in your CSS that are not in a cascade layer win over the stylesheet’s layered rules. A
global rule such as
button { padding: 0 }reaches the SDK’s buttons too. - When the
darkclass is on<html>, the stylesheet also setscolor-scheme: darkon that element, which changes your page’s scrollbars and unstyled form controls.