# HTMX Learning Guide
**Last Updated**: December 2024
## Overview
This document explains HTMX patterns used in this CV website project, with practical examples from the codebase. Use this as a learning resource for understanding HTMX concepts.
## Table of Contents
1. [Core Concepts](#core-concepts)
2. [Out-of-Band Swaps (OOB)](#out-of-band-swaps-oob)
3. [Language Switch Pattern](#language-switch-pattern)
4. [Toggle Patterns](#toggle-patterns)
5. [Contact Form Pattern](#contact-form-pattern)
6. [Skeleton Loaders](#skeleton-loaders)
7. [HTML Invoker Commands API](#html-invoker-commands-api)
8. [Lazy Loading Web Components](#lazy-loading-web-components)
9. [Common Attributes Reference](#common-attributes-reference)
---
## Core Concepts
### What is HTMX?
HTMX allows you to build modern user interfaces with simple HTML attributes instead of JavaScript. It extends HTML with attributes that enable:
- **AJAX requests** from any element (not just links/forms)
- **Partial page updates** without full page reloads
- **CSS transitions** on swaps
- **WebSocket/SSE** support
### Basic Example
```html
```
---
## Out-of-Band Swaps (OOB)
### The Problem
Normal HTMX swaps can only update ONE target element. But what if you need to update MULTIPLE elements with a single request?
**Example**: When switching languages, we need to update:
- Language selector buttons (show which is active)
- Page 1 content (header, experience, education)
- Page 2 content (awards, projects, courses)
- Footer
### The Solution: `hx-swap-oob`
OOB (Out-of-Band) swaps let you update ANY element on the page by including it in your response with a matching `id`.
```html
Main content here
New sidebar content
5 new messages
```
### OOB Swap Types
| Attribute | Effect |
|-----------|--------|
| `hx-swap-oob="true"` | Replace inner HTML |
| `hx-swap-oob="innerHTML"` | Replace inner HTML |
| `hx-swap-oob="outerHTML"` | Replace entire element including itself |
| `hx-swap-oob="beforebegin"` | Insert before element |
| `hx-swap-oob="afterend"` | Insert after element |
---
## Language Switch Pattern
**File**: `templates/language-switch.html`
This is the most complex HTMX pattern in the project - updating the entire CV content when switching languages.
### How It Works
1. **User clicks language button** (EN or ES)
2. **HTMX sends request** to `/switch-language?lang=es`
3. **Server renders new content** for both pages in the selected language
4. **OOB swaps update** both page containers atomically
### The Template Structure
```html