# HTMX Integration Patterns - Public Web Frontend
**Last Updated:** November 18, 2025
---
## Overview
This document outlines HTMX usage patterns, best practices, and common implementations for the Code of Conquest web frontend.
**HTMX Benefits:**
- Server-side rendering with dynamic interactions
- No JavaScript framework overhead
- Progressive enhancement (works without JS)
- Clean separation of concerns
- Natural integration with Flask/Jinja2
---
## Core HTMX Attributes
### hx-get / hx-post / hx-put / hx-delete
Make HTTP requests from HTML elements:
```html
```
### hx-target
Specify where to insert the response:
```html
```
### hx-swap
Control how content is swapped:
```html
```
### hx-trigger
Specify what triggers the request:
```html
...
...
Status: ...
...
```
---
## Common Patterns
### Form Submission
**Pattern:** Submit form via AJAX, replace form with result
```html
```
**Backend Response:**
```python
@characters_bp.route('/', methods=['POST'])
def create_character():
# Create character via API
response = api_client.post('/characters', request.form)
if response.status_code == 200:
character = response.json()['result']
return render_template('partials/character_card.html', character=character)
else:
return render_template('partials/form_error.html', error=response.json()['error'])
```
### Delete with Confirmation
**Pattern:** Confirm before deleting, remove element on success
```html
{{ character.name }}
```
**Backend Response (empty for delete):**
```python
@characters_bp.route('/', methods=['DELETE'])
def delete_character(character_id):
api_client.delete(f'/characters/{character_id}')
return '', 200 # Empty response removes element
```
### Search/Filter
**Pattern:** Live search with debouncing
```html
Searching...