Learn how to use various styling libraries in your project, including Tailwind, styled-components, styled-jsx, and CSS Modules.
tailwindcss
dependency to your package.json
file in the JavaScript asset folder.tailwind.css
file in your styles directory. Then, import that file in your top-level component with the base Tailwind layer directives.styled-components
dependency to your package.json
file in the JavaScript asset folder.useInlineHeadAsset()
, and wrap the components you want to style in it. See the StyledComponentsRegistry.jsx example file for more details.Wrapper
prop on the Island
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:Wrapper
prop you must import the component with a ?client
suffix to make sure it can be bundled for the client.styled
from 'styled-components'
and use it to style your components.styled-jsx
in your project:
styled-jsx-components
dependency to your package.json
file in the JavaScript asset folder.useInlineHeadAsset()
. See the StyledJSXRegistry.jsx example file for more details.styled-jsx
registry component must also be wrapped on any <Island>
usage to prevent hydration mismatches or missing styles on initial load. Note that styled-jsx'
s implementation depends on useId()
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.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..module.css
, which will return a CSS module object:
<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.className
that the React component code conditionally renders in your JSX.Wrapper
on any <Island>
component if there are styles within the island.