Quickstart: Qwik
1 Create the project
shellnpm create qwik@rc empty css-hooks-playground cd css-hooks-playground
2 Install CSS Hooks
shellnpm install @css-hooks/qwik@next
3 Create the styling module
src/css.tsimport { createHooks, mergeStyles } from "@css-hooks/qwik"; export const { on, styleSheet } = createHooks("&:hover"); export { mergeStyles };
4 Render the stylesheet
src/root.tsximport { component$ } from "@qwik.dev/core"; import { DocumentHeadTags, RouterOutlet, useLocation, useQwikRouter, } from "@qwik.dev/router"; +import { styleSheet } from "./css"; import "./global.css"; export default component$(() => { useQwikRouter(); const { url } = useLocation(); /** * This is the root of a QwikRouter site. It contains the document's `<head>` and `<body>`. You can adjust them as you see fit. */ return ( <> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <DocumentHeadTags /> + <style dangerouslySetInnerHTML={styleSheet()} /> <link rel="canonical" href={url.href} /> </head> <body> <RouterOutlet /> </body> </> ); });
5 Create a hover effect
Replace the contents of src/routes/index.tsx with the following:
src/routes/index.tsximport { component$ } from "@qwik.dev/core"; import { on } from "../css"; export default component$(() => ( <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:5173.
Next steps
Continue to Hooks and conditions to declare more hooks, then read Applying styles for composition patterns.