Softwr

Web Development · head to head

HTMX vs Preact

HTMX logo

HTMX

Web Development

Lightweight JavaScript library enabling AJAX, WebSockets, and server-sent events in HTML

From
Free
Rated
-
Preact logo

Preact

Web Development

3kB alternative to React with the same modern API

From
Free
Rated
-

The short version

  • Each has a real cost: HTMX best suited for server-rendered architectures, not pure client-side SPAs; Preact compatibility through preact/compat is good but not total, and some React libraries break in ways that are hard to diagnose
  • They diverge on capability: HTMX covers AJAX requests, Preact covers 3kB runtime.

Where they differ

Only the attributes on which HTMX and Preact actually diverge.

Attributes where HTMX and Preact differ
AttributeHTMXPreact
Pricing modelopen-sourceOpen source, no licence fee

Identical on both: starting price (Free), free tier (Yes), platforms (Web), user rating (Not yet rated), category (Web Development).

What each one covers

Drawn from each product's published feature list. An absence here means we hold no record of it - not that the product lacks it.

Only in HTMX

  • AJAX requests
  • HTTP verb support
  • DOM targeting
  • Swap strategies
  • WebSocket support
  • Server-sent events
  • Out-of-band updates

Only in Preact

  • 3kB runtime
  • preact/compat
  • Same modern API
  • Fast rendering

What people use each for

The jobs each tool is most often brought in to do.

HTMX

  • Building interactive applications without JavaScript framework complexitynot Preact
  • Server-rendered applications requiring dynamic updatesnot Preact
  • Adding interactivity to existing server-side applicationsnot Preact
  • Hypermedia-driven applications using HTML-first approachesnot Preact

Preact

  • Embedded widgets that load inside someone else’s page and must stay smallnot HTMX
  • Marketing and content sites where JavaScript payload affects Core Web Vitalsnot HTMX
  • Applications targeting low-bandwidth or low-powered devicesnot HTMX

Where each one falls short

Documented limitations, not opinions. Every one is a constraint you would hit in normal use.

HTMX

  • Best suited for server-rendered architectures, not pure client-side SPAs
  • Limited client-side state management capabilities compared to frameworks
  • Smaller ecosystem with fewer third-party libraries and tools
  • Learning curve for developers from JavaScript framework backgrounds

Preact

  • Compatibility through preact/compat is good but not total, and some React libraries break in ways that are hard to diagnose
  • Behavioural differences from React exist in edge cases, particularly around event handling
  • A much smaller community, so unusual problems have fewer existing answers than React

Pricing, plan by plan

HTMX

Free

No published plan breakdown. See the HTMX review.

Preact

Free
  • PreactFree
    • Full library
    • Commercial use permitted
    • No usage limits

Which should you pick?

Choose HTMX if

  • You need ajax requests.
  • You want to start without paying.
  • You also want http verb support.

Choose Preact if

  • You need 3kb runtime.
  • You want to start without paying.
  • You also want preact/compat.

Questions people ask

Is HTMX or Preact better?
Neither clearly leads. HTMX starts at Free and Preact at Free, and user ratings are close enough to be indistinguishable. Choose on capability and platform support.
Which is cheaper, HTMX or Preact?
HTMX starts at Free and Preact at Free.
Does HTMX or Preact run on more platforms?
Both run on Web, so platform support will not decide this one for you.
Can I use HTMX for free?
Both have a free tier, so you can try either at no cost before committing.
What is HTMX best used for?
HTMX is most often used for building interactive applications without javascript framework complexity, server-rendered applications requiring dynamic updates, adding interactivity to existing server-side applications, hypermedia-driven applications using html-first approaches. Of those, building interactive applications without javascript framework complexity and server-rendered applications requiring dynamic updates are not what Preact is typically brought in for.
What can HTMX do that Preact cannot?
HTMX covers AJAX requests, HTTP verb support, DOM targeting, Swap strategies. Preact covers 3kB runtime, preact/compat, Same modern API, Fast rendering.

Answered from the vendors’ own pages

HTMX: How big is the HTMX JavaScript library?

HTMX is only 16 kilobytes minified and gzipped with zero external dependencies.

Source
Preact: Is Preact free?

Yes, open source under the MIT licence.

HTMX: Can HTMX work with JSON APIs?

While HTMX is optimized for HTML responses, it can work with JSON through additional configuration and response handling.

Source
Preact: Can I use React libraries with Preact?

Most, through the preact/compat layer. Compatibility is good but not complete, so libraries relying on React internals can break.

HTMX: Does HTMX support real-time features like WebSockets?

Yes, HTMX includes support for WebSockets and server-sent events for real-time bidirectional communication.

Source
Preact: Why choose Preact over React?

Bundle size, almost always. If payload is not a binding constraint, React’s ecosystem is usually the better trade.

Share

Related pages

Other head to heads