Logo Htmx

Htmx

Cộng đồng
mintarasss
htmx

Expert guidance for building web applications with htmx — the library that gives HTML superpowers by extending it with attributes for AJAX, CSS transitions, WebSockets, and Server-Sent Events. Use this skill whenever the user is working with htmx attributes (hx-get, hx-post, hx-swap, hx-trigger, hx-target, etc.), building hypermedia-driven applications, writing server endpoints that return HTML fragments, implementing patterns like click-to-edit, infinite scroll, active search, lazy loading, inline validation, or any UI pattern that uses HTML-over-the-wire instead of JSON APIs. Also use this skill when the user mentions htmx by name, asks about AJAX without JavaScript frameworks, wants to add interactivity to server-rendered HTML, or is working with any hx-* attributes. Trigger even for partial mentions like 'how do I make this form submit without page reload' or 'load content dynamically' in projects that use htmx.

Tổng quan

Nhà phát hànhmintarasss
Kho mãhtmx-skill
Tên kỹ nănghtmx
Sao
47
Bản fork
2
Tệp đi kèm
4
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 4 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được mintarasss công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Htmx trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/mintarasss/htmx-skill/tree/main/htmx
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mintarasss/htmx-skill.git /tmp/htmx-skill
mkdir -p .claude/skills
cp -r /tmp/htmx-skill/htmx .claude/skills/htmx
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Htmx trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Htmx ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Htmx không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

htmx Development Guide

htmx gives you access to AJAX, CSS Transitions, WebSockets, and Server-Sent Events directly in HTML using attributes. The core idea: any element can issue HTTP requests, and the response is HTML that gets swapped into the DOM.

The Mental Model

In traditional web apps, only <a> and <form> can make HTTP requests, only click and submit trigger them, and only the full page gets replaced. htmx removes these constraints:

  • Any element can issue a request (<button>, <div>, <span>, <tr>, etc.)
  • Any event can trigger it (click, input, revealed, load, custom events, polling)
  • Any HTTP verb works (GET, POST, PUT, PATCH, DELETE)
  • Any part of the page can be the swap target

The server returns HTML fragments, not JSON. This is the fundamental architectural difference from SPA frameworks.

Core Attributes

HTTP Verbs

AttributeDescription
hx-getIssues a GET request
hx-postIssues a POST request
hx-putIssues a PUT request
hx-patchIssues a PATCH request
hx-deleteIssues a DELETE request

None of the HTTP verb attributes are inherited. An empty value (e.g., hx-get="") requests the current URL.

Example — a button that loads content:

html
<button hx-get="/api/data" hx-target="#result" hx-swap="innerHTML">
  Load Data
</button>
<div id="result"></div>

hx-trigger — What Causes the Request

Controls which event fires the request. Default triggers: click for most elements, change for inputs/selects/textareas, submit for forms.

Syntax: hx-trigger="<event>[<filter>] <modifiers>"

Modifiers:

  • once — trigger only once
  • changed — only if the element's value changed
  • delay:<time> — debounce (e.g., delay:500ms)
  • throttle:<time> — throttle (e.g., throttle:1s)
  • from:<selector> — listen on a different element (supports document, window, closest <sel>, find <sel>, next, previous)
  • target:<selector> — only if the event target matches
  • consume — stop event propagation
  • queue:<first|last|all|none> — queuing strategy

Event filters use JavaScript expressions in brackets:

html
<input hx-get="/search" hx-trigger="keyup[key=='Enter']"/>
<button hx-get="/action" hx-trigger="click[ctrlKey]">Ctrl+Click</button>

Special triggers:

  • load — fires when element loads
  • revealed — fires when element scrolls into viewport
  • intersect — uses IntersectionObserver (with root: and threshold: options)
  • every <time> — polling (e.g., every 2s)

Multiple triggers are comma-separated:

html
<input hx-post="/search"
       hx-trigger="input changed delay:500ms, keyup[key=='Enter'], load"
       hx-target="#results">

Not inherited.

hx-target — Where the Response Goes

CSS selector for the element that receives the response HTML. Defaults to the element making the request.

Extended selectors:

  • this — the element itself
  • closest <sel> — nearest ancestor matching selector
  • find <sel> — first descendant matching selector
  • next / next <sel> — next sibling (optionally matching selector)
  • previous / previous <sel> — previous sibling
html
<button hx-get="/info" hx-target="closest .card">Load</button>
<button hx-delete="/item/1" hx-target="closest tr">Delete</button>

Inherited.

hx-swap — How Content is Replaced

Controls the swap strategy. Default: innerHTML.

ValueDescription
innerHTMLReplace inner content of target
outerHTMLReplace the entire target element
textContentReplace text content (no HTML parsing)
beforebeginInsert before target
afterbeginInsert at start of target
beforeendInsert at end of target
afterendInsert after target
deleteDelete the target element
noneDo nothing with the response

Swap modifiers (appended with space):

  • swap:<time> — delay before swap (e.g., swap:1s for fade-out animations)
  • settle:<time> — delay before settling (e.g., settle:1s for fade-in)
  • transition:true — use View Transitions API
  • ignoreTitle — don't update page title
  • scroll:top / scroll:bottom — scroll target after swap
  • show:top / show:bottom — scroll element into view
  • focus-scroll:true/false — scroll focused element into view
html
<button hx-delete="/item" hx-swap="outerHTML swap:1s">Delete with fade</button>

Inherited.

hx-swap-oob — Out of Band Swaps

Allows response elements to update multiple parts of the page simultaneously. Add hx-swap-oob="true" (or a swap strategy) to elements in the response that should be swapped into their matching id location.

html
<!-- Server response can include: -->
<div id="main-content">Primary content here</div>
<div id="notification-count" hx-swap-oob="true">5</div>
<div id="sidebar" hx-swap-oob="outerHTML">Updated sidebar</div>

Use <template> to wrap elements that can't exist standalone (like <tr>, <td>, <option>):

html
<template><tr id="row-1" hx-swap-oob="true"><td>Updated</td></tr></template>

Not inherited.

hx-vals — Additional Request Parameters

Add extra values to requests in JSON format:

html
<button hx-post="/action" hx-vals='{"key": "value"}'>Go</button>

Dynamic values with js: prefix:

html
<button hx-post="/action" hx-vals='js:{timestamp: Date.now()}'>Go</button>

Inherited. Child values override parent values.

hx-include — Include Extra Inputs

Include input values from other elements:

html
<button hx-post="/search" hx-include="#search-form">Search</button>
<button hx-post="/save" hx-include="closest form">Save</button>

hx-select and hx-select-oob — Cherry-pick Response Content

hx-select picks a portion of the response to swap. hx-select-oob picks portions for out-of-band swaps elsewhere on the page.

html
<div hx-get="/page" hx-select="#content" hx-select-oob="#sidebar,#nav">

Both inherited.

Important Patterns

Inheritance

Most htmx attributes inherit from parent elements. Place shared attributes on a container:

html
<div hx-target="#result" hx-swap="outerHTML" hx-indicator="#spinner">
  <button hx-get="/one">One</button>
  <button hx-get="/two">Two</button>
</div>

Control with hx-disinherit (disable) or hx-inherit (enable when globally disabled). HTTP verb attributes (hx-get, hx-post, etc.) and hx-trigger are never inherited.

Loading Indicators

html
<button hx-get="/data" hx-indicator="#spinner">Load</button>
<span id="spinner" class="htmx-indicator">Loading...</span>

htmx adds htmx-request class to the indicator during requests. Default CSS transitions opacity from 0 to 1.

CSS Transitions & Animations

htmx applies CSS classes at different lifecycle stages:

  • htmx-request — during the request (on the indicator or triggering element)
  • htmx-swapping — during the swap phase
  • htmx-settling — during the settling phase
  • htmx-added — on newly added content before settling

Use these with CSS transitions for smooth animations:

css
tr.htmx-swapping td { opacity: 0; transition: opacity 1s ease-out; }
.htmx-added { opacity: 0; }
#element { transition: opacity 300ms ease-in; }

Boosting

hx-boost="true" progressively enhances links and forms to use AJAX:

html
<nav hx-boost="true">
  <a href="/page1">Page 1</a>  <!-- Now uses AJAX -->
  <a href="/page2">Page 2</a>
</nav>

Confirmation and Prompts

html
<button hx-delete="/item/1" hx-confirm="Are you sure?">Delete</button>
<button hx-post="/rename" hx-prompt="Enter new name">Rename</button>

Prompt value is sent in the HX-Prompt request header.

Synchronization

Prevent race conditions between related requests:

html
<form hx-post="/validate" hx-sync="closest form:abort">
  <input hx-post="/validate-email" hx-sync="closest form:abort"/>
  <button type="submit">Submit</button>
</form>

Strategies: drop, abort, replace, queue first, queue last, queue all.

Inline Event Handling (hx-on)

html
<button hx-get="/data" hx-on::after-request="alert('Done!')">Load</button>
<form hx-on::after-request="if(event.detail.successful) this.reset()">

Double-colon :: is shorthand for htmx: prefix. this refers to the element, event is the event object.

Request and Response Headers

Request Headers (sent by htmx)

HeaderDescription
HX-RequestAlways "true"
HX-TriggerID of the triggered element
HX-Trigger-NameName of the triggered element
HX-TargetID of the target element
HX-Current-URLCurrent browser URL
HX-Boosted"true" if boosted
HX-PromptUser response to hx-prompt

Response Headers (sent by server)

HeaderDescription
HX-TriggerTrigger client-side events
HX-Trigger-After-SwapTrigger events after swap
HX-Trigger-After-SettleTrigger events after settle
HX-Push-UrlPush URL to browser history
HX-Replace-UrlReplace current URL
HX-RedirectFull page redirect
HX-LocationClient-side redirect (AJAX)
HX-RefreshFull page refresh
HX-ReswapOverride swap strategy
HX-RetargetOverride swap target
HX-ReselectOverride hx-select

HX-Trigger header can carry data:

HX-Trigger: {"showMessage": "Item deleted", "itemCount": "5"}

Listen for these events:

html
<div hx-trigger="showMessage from:body" hx-get="/notifications">

Response Handling

By default, 2xx responses are swapped, 4xx/5xx are not. This is configurable:

html
<meta name="htmx-config" content='{
  "responseHandling": [
    {"code": "204", "swap": false},
    {"code": "[23]..", "swap": true},
    {"code": "422", "swap": true, "error": true},
    {"code": "[45]..", "swap": false, "error": true}
  ]
}'>

A 204 No Content response causes no swap. For DELETE, return 200 with empty body to clear the element.

Security Considerations

  • htmx.config.selfRequestsOnly (default: true) — restricts AJAX to same domain
  • Use hx-disable on containers with user-generated content
  • hx-vals with js: prefix evaluates JavaScript — sanitize user input
  • Set CSP nonces via htmx.config.inlineScriptNonce and htmx.config.inlineStyleNonce
  • htmx.config.allowEval can be set to false for strict CSP

Configuration

Set via meta tag or JavaScript:

html
<meta name="htmx-config" content='{"defaultSwapStyle":"outerHTML"}'>

Key config options: defaultSwapStyle (default: innerHTML), defaultSettleDelay (default: 20ms), historyCacheSize (default: 10), selfRequestsOnly (default: true), globalViewTransitions (default: false).

Reference Files

For detailed information, consult these reference files:

  • references/attributes.md — Complete attribute reference with all options and edge cases
  • references/patterns.md — Common UI patterns with full HTML and server-side examples
  • references/extensions.md — SSE, WebSocket, Idiomorph, head-support, preload, response-targets, and building custom extensions
  • references/server-side.md — Server integration patterns, response headers, and framework examples

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Htmx làm được gì?

Expert guidance for building web applications with htmx — the library that gives HTML superpowers by extending it with attributes for AJAX, CSS transitions, WebSockets, and Server-Sent Events. Use this skill whenever the user is working with htmx attributes (hx-get, hx-post, hx-swap, hx-trigger, hx-target, etc.), building hypermedia-driven applications, writing server endpoints that return HTML fragments, implementing patterns like click-to-edit, infinite scroll, active search, lazy loading, inline validation, or any UI pattern that uses HTML-over-the-wire instead of JSON APIs. Also use thi...

Vì sao nên dùng Htmx trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Htmx là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Htmx trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/mintarasss/htmx-skill/tree/main/htmx. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Htmx?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Htmx với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Htmx với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Htmx có miễn phí không?

Có. Kỹ năng này được mintarasss phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇