Code Components work with a wide range of styling approaches, including CSS preprocessors, utility frameworks, and component/style libraries.
Because Code Components render inside a Shadow DOM, some tools that inject styles into the global document.head need additional configuration to scope styles correctly. Webflow provides utilities for popular CSS-in-JS libraries (e.g. Emotion, styled-components) so they can inject styles directly into the Shadow Root.
Most setups just require a small addition to your webpack configuration and an import in your component. For CSS-in-JS solutions, you’ll wrap your components in a Shadow DOM provider.
To use styled-components with code components, install the @webflow/styled-components-utils package and configure a global decorator to inject styles into the Shadow DOM.
To use Emotion with code components, install the @webflow/emotion-utils package and configure a global decorator to inject styles into the Shadow DOM.
In your terminal, run the following command to install the Emotion utility package:
This package requires the following peer dependencies:
Material UI uses Emotion for styling. Install the @webflow/emotion-utils package and configure a global decorator to inject styles into the Shadow DOM.
In your terminal, run the following command to install the Emotion utility package:
This package requires the following peer dependencies:
Shadcn/UI is a component library built on Tailwind CSS that provides pre-built, accessible React components. It works with code components but requires path alias configuration. Follow these steps after setting up Tailwind CSS:
Shadcn/UI uses path aliases that need to be configured in your webpack setup. Add this to your webpack configuration:
For detailed webpack configuration options, see the bundling and import guide.
Configure your project to use Sass with the following steps:
Configure your project to use Less with the following steps:
Learn about additional configuration options in the bundling and import guide.
If you’re getting errors when sharing to Webflow, try the following:
npx to ensure the correct version is being used.