htmx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHTMX Skill
HTMX 技能指南
Use this skill for HTMX implementation and integration. Read only the reference file(s) needed for the task.
本指南适用于HTMX的实现与集成。仅阅读任务所需的参考文件即可。
Quick Start
快速入门
- Identify the domain of the task (attributes, requests, swapping, events, patterns).
- Open the matching file from .
references/ - Implement using HTML-first, hypermedia-driven patterns.
- Validate that server responses return HTML fragments, not JSON.
- 确定任务所属领域(属性、请求、替换、事件、模式)。
- 从目录中打开对应的文件。
references/ - 采用HTML优先、超媒体驱动的模式进行实现。
- 验证服务器响应返回的是HTML片段而非JSON。
Critical Rules
核心规则
- HTMX expects HTML responses from the server, not JSON.
- Most attributes inherit to child elements. Not inherited: ,
hx-trigger,hx-on*,hx-swap-oob,hx-preserve,hx-history-elt. Usehx-validateorhx-disinheritto stop inheritance of other attributes.unset - Default swap strategy is . Always confirm the intended swap method.
innerHTML - Non-GET requests automatically include the closest enclosing form's values.
- Use for progressive enhancement — pages must work without JS.
hx-boost="true" - Escape all user-supplied content server-side to prevent XSS.
- HTMX adds/removes CSS classes during the request lifecycle — use these for transitions and indicators.
- All attributes can also be written as
hx-*for HTML validation compliance.data-hx-*
- HTMX期望服务器返回HTML响应,而非JSON。
- 大多数属性会继承到子元素。不继承的属性包括:、
hx-trigger、hx-on*、hx-swap-oob、hx-preserve、hx-history-elt。可使用hx-validate或hx-disinherit来阻止其他属性的继承。unset - 默认的替换策略是。请务必确认预期的替换方式。
innerHTML - 非GET请求会自动包含最近的父表单中的值。
- 使用实现渐进式增强——页面在无JavaScript的情况下也必须能正常工作。
hx-boost="true" - 在服务器端转义所有用户提供的内容以防止XSS攻击。
- HTMX会在请求生命周期中添加/移除CSS类——可利用这些类实现过渡效果和状态提示。
- 所有属性也可以写成
hx-*格式,以符合HTML验证规范。data-hx-*
Reference Map
参考文档映射
- All attributes, values, and modifiers:
hx-*references/attributes.md - Triggers, headers, parameters, CSRF, caching, CORS:
references/requests.md - Swap methods, targets, OOB swaps, morphing, view transitions:
references/swapping.md - Events, JS API, configuration, extensions, debugging:
references/events-api.md - Common UI patterns and examples:
references/patterns.md - Cross-file index and routing:
references/REFERENCE.md
- 所有属性、值及修饰符:
hx-*references/attributes.md - 触发器、请求头、参数、CSRF、缓存、CORS:
references/requests.md - 替换方法、目标元素、OOB替换、形态变化、视图过渡:
references/swapping.md - 事件、JS API、配置、扩展、调试:
references/events-api.md - 常见UI模式及示例:
references/patterns.md - 跨文件索引与路由:
references/REFERENCE.md
Task Routing
任务路由
- Adding HTMX behavior to elements ->
references/attributes.md - Configuring how/when requests fire ->
references/requests.md - Controlling where/how responses render ->
references/swapping.md - Handling events, JS interop, or config ->
references/events-api.md - Building common UI patterns (search, infinite scroll, modals, etc.) ->
references/patterns.md - Cross-cutting concerns or architecture -> then domain-specific files
references/REFERENCE.md
- 为元素添加HTMX行为 ->
references/attributes.md - 配置请求的触发方式/时机 ->
references/requests.md - 控制响应的渲染位置/方式 ->
references/swapping.md - 处理事件、JS交互或配置 ->
references/events-api.md - 构建常见UI模式(搜索、无限滚动、模态框等) ->
references/patterns.md - 跨领域问题或架构设计 -> 先查看,再查阅领域特定文件
references/REFERENCE.md