# HTMX 4 Integration Guide for Nebula
This document details htmx 4 enhancements and patterns optimized for our Go/Templ server-driven architecture.
## Why htmx 4?
htmx 4 introduces significant architectural improvements that align perfectly with Go-based server rendering:
- **Built-in SSE streaming** - Native support for `text/event-stream` responses
- **Morphing swaps** - Preserve DOM state during updates (forms, video, focus)
- **Partial tags** - Explicit multi-target updates in single responses
- **View Transitions API** - Smooth animated page transitions
- **Simplified extensions** - Page-wide, event-based, zero performance penalty
- **Enhanced request headers** - Better server-side request detection
---
## Installation
```html
```
**Note:** htmx 4 extensions are bundled in the htmx.org package at `/dist/ext/`. Do NOT use the separate `htmx-ext-*` packages which use the deprecated `defineExtension` API.
---
## Core Patterns for Go/Templ
### 1. Partial Updates with ``
The `` tag enables multiple targeted updates in a single response - perfect for Go handlers that need to update several page sections.
**Go Handler:**
```go
func handleAddToCart(w http.ResponseWriter, r *http.Request) {
// Return multiple partials in one response
components.CartPartials(cartData).Render(r.Context(), w)
}
```
**Templ Component:**
```templ
templ CartPartials(data CartData) {
{ strconv.Itoa(data.Count) }
@CartItem(data.NewItem)
{ data.FormattedTotal }
}
```
**HTML Trigger:**
```html
```
### 2. Morphing Swaps (Preserve State)
Use `innerMorph` or `outerMorph` to update content while preserving:
- Form input values
- Focus state
- Video/audio playback
- Scroll position
**Use Cases:**
```html