CSS and styling
SolidStart 2.0 introduces a completely revamped CSS rendering mechanism:
- CSS deduplication during server-side rendering works more consistently across the board.
- Hot module replacement (HMR) of route CSS is now directly managed by Vite instead of SolidStart.
- CSS in
lazy-loaded components is now properly server-side rendered and does not result in flashes of unstyled content. - Client-side navigation now mounts new CSS directly via Vite instead of SolidStart.
- Server HTML responses no longer have to include the whole assets manifest.
- Client-side navigation no longer unmounts old CSS, more closely following Vite's native behaviour.
Styling components
You can import CSS using ESM syntax anywhere within the component tree. Styles imported as such, are globally mounted in your app.
Locally scoped styles
SolidStart supports CSS modules, allowing you to locally scope the imported CSS.
As is standard with Vite, any file ending with .module.css, .module.scss or .module.sass is considered a CSS module. Reference the generated css class names via the imported object, e.g. styles.card.
Route-specific global styles
Imported CSS stays in the document when navigating to different routes. Therefore routes with different global styles will overlap each other. There exist several strategies to get around this limitation:
Apply :has pseudo-class
If you only have to apply few global CSS rules for one specific route, you can use the CSS :has pseudo-class, to tie the global CSS to the route:
Import with ?url
If the route depends on complex global CSS (e.g. using Tailwind only in one specific route), optimizing all selectors with :has might not always be possible. Instead you can import the CSS file by URL and mount it through JSX:
Lazy loading
Lazy loading components with CSS is now fully supported in SolidStart 2.0 and no longer results in flashes of unstyled content (FOUC):
Other ways to style components
SolidStart is built on top of Solid, meaning styling is not limited to CSS. To see other ways to style components, see the styling section in the Solid documentation.