Add styles to a working component
The counter’s style section appears before its template:
<script>let count: Signal<i32> = Signal::new(0);let increment = move || count.update(|n| *n += 1);</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }button { padding: 8px 12px; }</style><button onclick={increment}>Clicked {count} times</button> Save it as crates/demos/demos/counter.wisp and run cargo run -p vapors-app --example demo -- counter. Add background-color: #3a7bd5; color: #ffffff; to the button rule, close the window and rebuild. The button should now have a blue background and white text.
Rules apply to this component
The button selector styles buttons created by this component. A child component’s elements have their own scope, so a parent’s rule does not reach them. The composition lesson shows separate parent and child styles.
Use :global(...) for an element the component did not create. Here, :global(body) sets the host document’s body to flex layout. The button therefore becomes a flex item, which this revision requires for its layout.
Add interaction states
Add this rule and move the pointer over the button after rebuilding:
button:hover { background-color: #245a9e; } The document updates the :hover state from pointer input. No Rust event handler is needed for this color change.
Validation and supported CSS
The CSS engine refuses unsupported properties and values with source information. At the revision used by these lessons, style-section errors are reported when the document updates at runtime. Newer compiler validation is described separately in CSS and styling.
See that reference for selectors, custom properties, supported values and scoping rules. Passing the template checker alone does not establish that this revision can render a stylesheet.