For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
GuidesExamplesChangelog
GuidesExamplesChangelog
  • Code Components
    • Introduction
    • Component Architecture
    • Styling Components
  • Importing Code Components
    • Quick start: Importing code components
    • Installation
    • Define a code component
    • Bundling & Import
  • Generating AI Code Components
    • Quick start: Generating AI code components
  • FAQs
    • FAQs and troubleshooting
  • Reference
    • Webflow CLI
    • Prop Types
LogoLogo
Resources
Get started
On this page
  • How Shadow DOM affects styling
  • Adding styles to your code components
  • CSS capabilities
  • Advanced configuration
Code Components

Styling components

Style your code components using site variables, inherited properties, and tag selectors.
Was this page helpful?
Previous

Quick start: Importing code components

Import React components into Webflow with DevLink
Next
Built with

Imported components support standard React styling approaches, but with important considerations for Shadow DOM isolation.

How Shadow DOM affects styling

Code components render in Shadow DOM, which creates an isolated styling boundary. This means:

  • Your component styles won’t affect the rest of the page
  • Page styles won’t affect your component
  • You need to explicitly connect to external styles

Rendering components in Shadow DOM prevents style conflicts to ensure your component looks and behaves as expected. However, this also means you need to explicitly connect to external styles like site variables, inherited properties, or tag selectors.

Adding styles to your code components

To ensure your code components are styled correctly, you can import your styles directly into your *.webflow.tsx file.

Button.webflow.tsx
1import { props } from '@webflow/data-types';
2import { declareComponent } from '@webflow/react';
3import { Button } from './Button';

Adding global styles

If you want to apply styles across all components, you can import your styles into a global decorators file.

1import "./globals.css";

Then reference it in your webflow.json. Once applied, all components will inherit the styles from the global css file.

webflow.json
1{
2 "library": {
3 "globals": "./src/globals.ts"
4 }
5}

CSS capabilities

The following table shows which CSS features work within Shadow DOM:

FeatureWorks in Shadow DOMHow to use
Site variables✅ Yesvar(--background-primary, fallback)
Inherited properties✅ Yesfont-family: inherit
Tag selectors✅ YesEnable with applyTagSelectors: true
Site classes❌ NoUse component-specific classes

Site variables

Reference a site’s variables in your components:

Button.module.css
1.button {
2 color: var(--background-primary, #000);
3 }

To get the exact variable name, click “Copy CSS” in the three-dot menu next to any variable in the Variables panel.

Inherited properties

CSS properties set to inherit work across Shadow DOM boundaries. Your component inherits styles from the parent HTML element:

Button.module.css
1.button {
2 color: var(--background-primary, #000);
3 font-family: inherit;
4 }

For example, if your component is placed inside a <div> with font-family: sans-serif, setting font-family: inherit in your component will use sans-serif.

Tag selectors

Tag selectors (like h1, p, button) defined in your site’s CSS can be automatically applied to your component. Enable this with the applyTagSelectors option in your component definition file.

Button.webflow.tsx
1import { declareComponent } from '@webflow/react';
2import { Button } from './Button';
3
4export default declareComponent(Button, {
5 name: 'Button',
6 options: {
7 applyTagSelectors: true,
8 },
9});

Advanced configuration

Code components support modern CSS frameworks and libraries, but some require specific configuration for Shadow DOM compatibility. For guidance on using CSS frameworks and component libraries with code components, see the frameworks and libraries guide.