Last modified: August 22, 2025
In this guide, learn about the different ways to include styling in your CMS React project. You can also refer to the styling example project for working examples of supported styling methods, including a number of major styling libraries. Below, learn more about each of the following methods:
Tailwind
Tailwind CSS is a framework designed to speed up the building process by providing utility classes for styling your markup without needing to write custom CSS. You can learn more about Tailwind CSS on HubSpot’s blog. To configure Tailwind for your components:- Add the
tailwindcss
dependency to yourpackage.json
file in the JavaScript asset folder.
- Add a Tailwind configuration file to your project subcomponent.
- Add a PostCSS configuration file to your project subcomponent, then import the Tailwind configuration file and include Tailwind as a plugin along with any Tailwind-specific configuration.
- Create a
tailwind.css
file in your styles directory. Then, import that file in your top-level component with the base Tailwind layer directives.
styled-components
styled-components is a library that enables you to write CSS in JavaScript and inject styles dynamically. Learn more about the basics of styled-components. To use styled-components in your project:- Add the
styled-components
dependency to yourpackage.json
file in the JavaScript asset folder.
- Create a registry component using the styled-components server-side rendering API and
useInlineHeadAsset()
, and wrap the components you want to style in it. See the StyledComponentsRegistry.jsx example file for more details. - For each island you’re using, you must wrap each subtree in a registry to capture styles when rendering on the server. To make this easier, you may use the
Wrapper
prop on theIsland
component to wrap the contents without needing to edit the island components themselves. Note that this prop also lets you configure this once by replacing all instances of<Island />
with a<StyledIsland />
component that looks similar to the following:
Please note:As shown above, when using the
Wrapper
prop you must import the component with a ?client
suffix to make sure it can be bundled for the client.- You can now import
styled
from'styled-components'
and use it to style your components.
styled-jsx
styled-jsx is a library that enables you to write encapsulated and scope CSS to style your components. By setting styles at the individual component level, you can add, change, and delete styles for one component without impacting others. To usestyled-jsx
in your project:
- Add the
styled-jsx-components
dependency to yourpackage.json
file in the JavaScript asset folder.
- Create a registry component using the server-side rendering API and
useInlineHeadAsset()
. See the StyledJSXRegistry.jsx example file for more details. - The
styled-jsx
registry component must also be wrapped on any<Island>
usage to prevent hydration mismatches or missing styles on initial load. Note thatstyled-jsx'
s implementation depends onuseId()
hooks in a way that can cause mismatches if not properly configured. See the StyledJSXIsland.jsx example file for an easier pattern of replacing all direct<Island />
usage.
- You can now use
styled-jsx
to style your components, including<style jsx>{`/_ CSS here _/`}</style>
patterns. See example below, which is copied from the InteractiveStyledJSXComponent.jsx example file.
CSS Modules
CSS Modules is a CSS file where all class names and animation names are scoped locally by default. You can use CSS Modules within any React component by importing a file ending in.module.css
, which will return a CSS module object:
- A
<style>
tag will automatically be inserted into the page when the component is rendered server-side or when it’s dynamically rendered in the browser. - Those styles will automatically be namespaced so they don’t interfere with anything else on the page.
Dynamic styles based on props
If you need to dynamically adjust styles based on props, try one of the following options:- If you need conditional styling that is either on or off, you can have a
className
that the React component code conditionally renders in your JSX. - If you need dynamic styling that is not on or off, but rather a specific color or number that you need to apply to your styles:
- You can define CSS custom properties in your CSS or CSS Modules code and inject new CSS custom property values via React.
- Or use React to set inline styles on the specific part of the module HTML.
Using other CSS-in-JS libraries
CMS React projects support any CSS-in-JS libraries that provide a server-side rendering API and don’t depend on a Babel plugin. The same registry patterns described above can be generalized for other libraries to emit CSS to include as part of the server-side render. You’ll also need to include the registry as aWrapper
on any <Island>
component if there are styles within the island.