---
title: HTMX
date: 2025-06-07 19:30:00
background: bg-[#ff5f4d]
tags:
- frontend
- javascript
- htmx
categories:
- Programming
intro: |
A modern, minimal JavaScript library that allows you to create dynamic web interfaces using HTML attributes.
plugins:
- copyCode
---
## Getting Started {.cols-3}
### CDN Import
```html
```
### Basic Usage
```html
```
### Server Response
```html
Hello from server
```
## Core Attributes {.cols-3}
### `hx-get`, `hx-post`, etc.
```html
Load Page
```
### `hx-target`
```html
```
### `hx-trigger`
```html
```
## Swap & Out of Band {.cols-3}
### `hx-swap`
```html
```
* `outerHTML`
* `innerHTML`
* `beforebegin`, `afterbegin`, etc.
### `hx-swap-oob`
```html
```
*Useful for global updates from partials.*
### Swap Modifiers
```html
hx-swap="outerHTML transition:true swap:1s"
```
## Forms & Events {.cols-3}
### Auto POST on Submit
```html
```
### `hx-include`
```html
```
### `hx-vals`
```html
```
## Advanced Features {.cols-3}
### Loading Indicator
```html
Loading...
```
### `hx-push-url`
```html
Go
```
### Polling
```html
```
## Events & Extensions {.cols-3}
### Listen to Events
```js
document.body.addEventListener('htmx:afterSwap', e => {
console.log("Swap complete");
});
```
### Event Hooks
* `htmx:beforeRequest`
* `htmx:afterSwap`
* `htmx:responseError`
### Extensions
```html
```
## Example Use Case {.cols-2}
### Python Backend (Flask)
```python
@app.route("/hello")
def hello():
return "Hello, HTMX!
"
```
### HTML Client
```html
```