htmx vs Selenium — Two Different Galaxies
One is a hypermedia library for modern web UIs, the other is a browser automation dinosaur. They don't even compete.
htmx
htmx lets you build dynamic UIs without writing a single line of JavaScript, while Selenium is a testing tool that simulates a user clicking around. If you're building, not testing, htmx wins by a mile.
Framing the Battle
Comparing htmx and Selenium is like comparing a hammer to a microscope. htmx is a frontend library that extends HTML with AJAX, CSS Transitions, and WebSockets, letting you build interactive UIs by adding attributes like hx-get or hx-post to your HTML. Selenium, on the other hand, is a browser automation framework for testing web apps by simulating user interactions. They serve completely different purposes: htmx is for building, Selenium is for testing. But since you asked, I'll compare them on the things that matter when you're choosing a tool for your stack.
Where htmx Wins
If you want to build a dynamic, modern web UI without drowning in JavaScript, htmx is your savior. It's 10KB minified and gzipped, requires no build step, and works with any backend that can serve HTML. You can add lazy loading, infinite scroll, form validation, and real-time updates with simple HTML attributes. For example, <button hx-get="/more" hx-target="#content"> loads content from /more and swaps it into #content. No event listeners, no fetch API, no state management. It's a joy to use for developers who hate the complexity of modern JS frameworks.
Where Selenium Holds Its Own
Selenium is the grizzled veteran of browser automation. It supports multiple browsers (Chrome, Firefox, Edge, Safari) and multiple languages (Java, Python, C#, Ruby, JavaScript). If you need to write end-to-end tests that click buttons, fill forms, and verify page states across browsers, Selenium is the industry standard. It's also free and open-source, with a massive ecosystem of tools like WebDriver and Grid for parallel testing. For automated regression testing of complex web apps, Selenium is still a solid choice.
The Gotcha: Purpose Mismatch
The biggest gotcha is that you can't use htmx to automate browser tests, and you can't use Selenium to build UIs. If you try to use htmx for testing, you'll be manually clicking around like a caveman. If you try to use Selenium for building UIs, you'll end up with a mess of scripts that simulate user interactions instead of actual UI logic. The hidden friction here is expectation management: these tools solve different problems. Don't pick one because you think it's a substitute for the other.
Practical Recommendation: If You're Starting Today
If you're building a new web application and want to keep your frontend simple, use htmx with your favorite backend (Python, Go, Ruby, PHP, whatever). You'll ship faster with less code. If you're writing automated tests for an existing web app (built with React, Angular, or even htmx), use Selenium (or consider Cypress or Playwright for better DX). But never confuse the two: one is for creating, the other is for verifying.
What Most Comparisons Get Wrong
Most comparisons pit these against each other as if they're competing for the same job. They're not. The real question is: what are you trying to do? If you need a lightweight way to add interactivity to server-rendered HTML, htmx is the answer. If you need to automate browser actions for testing, Selenium is one option among many (and honestly, Playwright is better). Comparing them directly is like asking whether you should use a screwdriver or a drill to cook dinner.
Quick Comparison
| Factor | htmx | selenium |
|---|---|---|
| Primary Use Case | Building interactive web UIs | Automating browser tests |
| Size | ~10KB min+gzip | ~10MB+ (WebDriver + browser drivers) |
| Learning Curve | Low: just HTML attributes | Medium: needs programming + WebDriver API |
| Browser Support | All modern browsers (via HTML) | All major browsers (Chrome, Firefox, Edge, Safari) |
| Language Support | Any backend (HTML/JS only on frontend) | Java, Python, C#, Ruby, JavaScript, Kotlin |
| Real-time Updates | Built-in via hx-trigger and WebSockets | Not applicable (testing only) |
| Pricing | Free, open-source (MIT) | Free, open-source (Apache 2.0) |
| Community Size | Growing, ~15k GitHub stars | Massive, ~30k+ GitHub stars, decades old |
The Verdict
Use htmx if: You're building a server-rendered web app and want to add interactivity without writing JavaScript or a heavy frontend framework.
Use selenium if: You need to write cross-browser automated tests for an existing web application, and you prefer a mature tool with broad language support.
Consider: If you want a better testing experience, look at Playwright — it's faster, has better APIs, and auto-waits. If you want even lighter interactivity than htmx, check out Alpine.js.
htmx lets you build dynamic UIs without writing a single line of JavaScript, while Selenium is a testing tool that simulates a user clicking around. If you're building, not testing, htmx wins by a mile.
Related Comparisons
Disagree? nice@nicepick.dev