HTMX and Alpine.js Tutorial
Learn HTMX and Alpine.js step by step: 28 lessons in 8 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- HTML-first interactivity: HTMX and Alpine.js Meet HTMX and Alpine.js: two small libraries that add server round trips and local state to plain HTML, with no build step and no JSON API.
- Setting Up: CDN, Versions and the In-Page Mock Server Add HTMX 2 and Alpine.js 3 with pinned CDN script tags, learn defer and load order, and read the tiny mock server every example in this track uses.
Alpine.js Basics
- Reactive State with x-data Learn Alpine.js state: x-data objects, x-text, x-show, @click, methods, getters, component scope, several components per page and x-init.
- Binding Attributes, Classes and Styles Bind HTML attributes with Alpine.js x-bind and the colon shorthand: dynamic classes, inline styles, disabled buttons, boolean attributes and x-model basics.
- Conditionals and Loops with x-if and x-for Render conditionally with x-if and repeat markup with x-for in Alpine.js: template tags, keys, index, nested loops, filtering with a getter and common mistakes.
- Forms and x-model Master Alpine.js forms: x-model on text, checkbox, radio, select and textarea, the .number .trim .lazy .debounce modifiers, live validation and @submit.prevent.
- Events, Modifiers and Refs Handle events in Alpine.js with @ listeners and modifiers like .prevent, .outside and .debounce, reach elements with x-ref, and talk between components with $dispatch.
Alpine.js Going Further
- Magic Properties, x-effect and Transitions Go further with Alpine.js: watch data with $watch, run code after updates with $nextTick, use x-effect, animate with x-transition, avoid flashes with x-cloak, and build modals with x-teleport.
- Reusable Components, Alpine.data and Stores Stop repeating inline x-data. Learn Alpine.data for reusable components with parameters, Alpine.store for global state, x-modelable, and the alpine:init event.
- Alpine Plugins and Other Features Tour the official Alpine.js plugins with live demos of collapse, intersect and mask, plus x-id, x-ignore and Alpine.bind for reusing attribute sets.
HTMX Basics
- Your First HTMX Request Send your first HTMX request with hx-get, choose where the reply goes with hx-target, see the default swap, and learn why the server answers with HTML, not JSON.
- Verbs, Triggers and Parameters Use hx-get, hx-post, hx-put, hx-patch and hx-delete, control when requests fire with hx-trigger, and decide what is sent with hx-vals, hx-include and hx-params.
- Targets and Swap Strategies Control where HTMX puts server HTML: hx-target selectors, every hx-swap strategy, swap modifiers, hx-select and out-of-band updates with hx-swap-oob.
- Forms, Validation and Submissions Submit forms with hx-post, return validation errors as HTML, validate fields on blur, disable buttons with hx-disabled-elt and confirm risky actions.
HTMX in Practice
- Loading States, Indicators and Feedback Show spinners with hx-indicator and the htmx-request class, animate swaps with htmx-swapping and htmx-settling, and stop race conditions with hx-sync.
- Common Interaction Patterns Build the interactions every site needs with HTMX: live search, click to edit, inline delete, load more, infinite scroll, lazy loading, polling, tabs and bulk actions.
- Events, Headers and JavaScript Integration Hook into HTMX with htmx:configRequest and htmx:beforeSwap, steer responses with HX-Trigger, HX-Retarget and HX-Reswap, and call htmx.ajax and htmx.process.
- URLs, History and Navigation Keep the address bar and Back button working with HTMX: hx-push-url, hx-replace-url, history snapshots, hx-boost and URLs that work without JavaScript.
HTMX and Alpine Together
- Using HTMX and Alpine.js Together Combine HTMX and Alpine.js safely: decide who owns which state, use Alpine inside swapped HTML, trigger requests with $dispatch and build server-filled modals.
- Server-Side Setup: Fragments, Partials and Security Return HTML fragments from Laravel, Django, Express or Flask, detect HX-Request, send CSRF tokens, escape output, and lock down HTMX and Alpine.js.
Projects
- Project: Todo List with HTMX and Alpine Build a todo list where the server owns the data: add, toggle and delete with HTMX, edit in place and filter with Alpine.js, and update counts out of band.
- Project: Live Search and Filterable Table Build a live-search table with HTMX and Alpine.js: debounced search, sortable columns, pagination with hx-get, column toggles and an empty state.
- Project: Shopping Cart and Product Quick View Build a shopping cart with HTMX and Alpine.js: add to cart with out-of-band badge updates, quantity steppers, server-computed totals and a quick-view modal.
- Project: Dashboard with Polling, Tabs and Toasts Build a dashboard with HTMX and Alpine.js: polling widgets with hx-trigger every, lazy-loaded tab panels, and toast notifications driven by HX-Trigger events.
Practice and Review
- Exercises with Solutions Twelve graded HTMX and Alpine.js exercises with runnable starters, hidden solutions and broken snippets to debug. Practice what you learned, then check your work.
- Common Mistakes and Debugging Fix the usual HTMX and Alpine.js bugs: missing x-data, x-for without template, x-cloak flashes, bad hx-target, 4xx and 5xx not swapping, plus debugging tips.
- Interview Questions 30 HTMX and Alpine.js interview questions with concise answers: hypermedia, swapping, triggers, reactivity, stores, security, testing and when to pick them.
- Cheat Sheet One-page HTMX and Alpine.js cheat sheet: attributes, triggers, swap values, headers, events, directives, magics and plugins, with two quick live checks.