Quickstart: Solid
1 Create the project
shellnpm create solid@latest css-hooks-playground -- --solid --template bare --ts --no-devtools cd css-hooks-playground
2 Install CSS Hooks
shellnpm install @css-hooks/solid@next
3 Create the styling module
src/css.tsimport { createHooks, mergeStyles } from "@css-hooks/solid"; export const { on, styleSheet } = createHooks("&:hover"); export { mergeStyles };
4 Render the stylesheet
src/Document.tsximport type { ParentProps } from 'solid-js'; import { HydrationScript } from '@solidjs/web'; +import { styleSheet } from './css'; // The document shell (the index.html replacement), picked up by the // src/Document.* convention; it must render the full <html> and ships no // client JS. <HydrationScript /> is stripped from the prerendered shell in // client mode and activates under `ssr: true`. Delete this file to fall // back to the plugin's built-in shell. export default function Document(props: ParentProps) { return ( <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="icon" href="/favicon.ico" /> <title>Solid App</title> + <style innerHTML={styleSheet()} /> <HydrationScript /> </head> <body>{props.children}</body> </html> ); }
5 Create a hover effect
Replace the contents of src/App.tsx with the following:
src/App.tsximport { on } from "./css"; export default function App() { return <button style={on("&:hover", { color: "red" })}>Hover me</button>; }
6 View the result
shellnpm run dev
By default, the development server is accessible at http://localhost:3000.
Next steps
Continue to Hooks and conditions to declare more hooks, then read Applying styles for composition patterns.