# Mixins, Styling, and Events ## What This Covers How to attach behavior, styles, and DOM-aware setup to host elements with `mix`. Read this when the task involves: - DOM event handling with `on(...)` - Static styling with `css(...)` and dynamic styling with `style` - Imperative DOM access via `ref(...)` - Navigation behavior on non-anchor elements with `link(...)` - Native click, pointer, and keyboard behavior with `on(...)`, plus attributes with `attrs(...)` - Element-level animation mixins from `remix/ui/animation` For richer animation work (springs, tweens, layout transitions), see `animate-elements.md`. For authoring custom mixins, see `create-mixins.md`. For component lifecycle and updates, see `component-model.md`. Compose behavior on host elements with `mix`. Pass a single mixin directly (`mix={on(...)}`), or an array when composing multiple mixins (`mix={[css(...), on(...)]}`). Core mixins are imported from `remix/ui`; animation mixins are imported from `remix/ui/animation`. ## `on(type, handler, capture?)` Attaches a typed DOM event handler. The handler receives the event and an `AbortSignal` that aborts when the handler is re-entered or the component is removed — this prevents race conditions: ```tsx { let query = event.currentTarget.value loading = true handle.update() let response = await fetch(`/search?q=${query}`, { signal }) let data = await response.json() if (signal.aborted) return results = data.results loading = false handle.update() })} /> ``` Multiple events on the same element: ```tsx