htmx SEO: what crawlers get from hx-get, boosting and lazy loads
htmx SEO depends on the raw HTML: boosted links keep real hrefs and forms, while hx-get with a load or revealed trigger leaves a placeholder crawlers may never fill.
By Crawlito · 9 min read
In short
Boosting with htmx is crawler-safe because it enhances ordinary a href links and forms; htmx's docs say boosted pages keep working when JavaScript is not enabled.
An element with hx-get and hx-trigger="load" or "revealed" ships only its placeholder in the HTML, so a crawler that does not run JavaScript sees the loading spinner, not the content.
An a element that has hx-get but no href gives crawlers no link to follow; Google says it cannot reliably extract URLs from a elements without an href.
htmx's docs say any URL you push into history must return a full page when visited directly, and say the server must check the HX-Request header to tell htmx requests from regular ones.
If one URL returns both fragments and full pages, htmx's docs say to send Vary: HX-Request so caches do not serve a fragment to a direct visitor or crawler.
htmx is crawler-friendly when the server sends the content and the links in its first response, and htmx only changes how they are fetched afterwards. Boosting fits that model: it keeps real <a href> links and real forms, so a crawler that ignores JavaScript still sees every destination. hx-get with a load or revealed trigger does not: the HTML holds only a placeholder, and the content arrives only for a client that runs htmx.
So the useful question for htmx SEO is not "does htmx hurt SEO" but "which of my htmx attributes leave the raw HTML incomplete". This post sorts the common attributes by that effect, then covers the server side: fragment URLs that must also work as full pages, the HX-Request header and caching.
Why htmx is different from a JavaScript framework
A typical single-page app ships an empty shell and builds the page in the browser. An htmx site usually renders HTML on the server, and htmx swaps pieces of server-rendered HTML into the page after it loads. That gives htmx a head start: the first response can already contain the full article, product or listing.
The catch is that htmx makes it easy to move content out of that first response. Any element can fetch HTML from any endpoint on any event, and the result looks identical in a browser whether the text was in the page or arrived 200 milliseconds later. A crawler that reads the raw response without running scripts only gets the first version. How often AI crawlers render JavaScript is covered in Do AI crawlers run JavaScript?; for planning, assume some of them read only the raw HTML.
htmx attributes sorted by what they leave in the raw HTML
Pattern
What is in the raw HTML
Crawler without JavaScript
A boosted container of links
Real <a href> links and real forms
Sees and can follow every link
<a href="/page" hx-get="/page">
A real link plus an htmx enhancement
Sees and can follow the link
<a hx-get="/page"> with no href
An anchor with no destination
No link to follow
<button hx-get="/panel"> that loads content on click
The rest of this post goes through these rows in order.
Boosted links keep real anchors and forms
htmx's boosting documentation describes an attribute that converts all anchor tags and forms inside an element into AJAX requests. You set it to true on a container, as in the example below. A boosted link issues a GET to the URL in its href, and a boosted form sends a GET or POST based on its method attribute. By default the response replaces the inner HTML of the <body>.
For a crawler, this markup is a plain navigation bar. The href values are in the HTML, and each one is a real page your server renders. htmx's documentation says boosting "degrades gracefully if javascript is not enabled": without scripts, the links and forms behave like normal browser navigation. That is the same property a crawler relies on.
A few details from htmx's attribute reference matter here:
Only links to the same domain that are not local anchors are boosted. External links behave normally.
The attribute is inherited, so you can set it once on <body> or a wrapper and turn it off for a child by setting it to false.
Boosted requests carry an HX-Boosted header, so your server can tell them apart from a direct visit.
The risk with boosting is on the server, not in the markup. If your server sees HX-Boosted and returns a trimmed response, the direct request without that header must still return the full page. More on that below.
hx-get on a link with no href hides the destination
htmx lets you put hx-get on any element, including an <a> with no href:
html
<!-- No destination in the markup -->
<a hx-get="/guides/install/" hx-target="#main" hx-push-url="true">Install guide</a>
<!-- Same behavior, with a real link underneath -->
<a href="/guides/install/" hx-get="/guides/install/" hx-target="#main" hx-push-url="true">Install guide</a>
The first version works for anyone with htmx loaded and gives crawlers nothing. Google's crawlable links guidance says it can generally crawl a link only if it is an <a> element with an href attribute, and that it "can't reliably extract URLs from <a> elements that don't have an href attribute". Whether any AI crawler reads URLs out of hx-get attributes is not documented by any operator, so do not count on it.
The fix is the second version, or simply boosting the parent element: keep the href, and let htmx enhance it. The general case for click handlers versus real anchors is in JavaScript links and crawler discovery; with htmx the change is usually one attribute.
hx-trigger="load" and "revealed" leave a placeholder
htmx's hx-trigger reference describes load as "triggered on load (useful for lazy-loading something)" and revealed as triggered "when an element is scrolled into the viewport". The official lazy-load example looks like this:
The raw HTML for this page contains a loading image with the alt text "Result loading...". The graph, and any text that comes with it, exists only after htmx runs and fetches /graph. A crawler that does not run JavaScript sees the spinner and nothing else.
That is fine for content you do not need crawlers to read, such as a personalised widget, a live chart or a cart count. It is a problem when the lazy part is the page's substance: product specs, reviews, the body of an article, a list of related pages.
What to do depends on why the content was deferred:
It was deferred for speed, but it is cheap to render. Move it into the main template and drop the hx-get. This is the most common case.
It is slow, but it is important. Render it on the server with caching, so the first response includes it, rather than fetching it on load.
It is genuinely secondary. Keep the lazy load, but put a short server-rendered summary or a link to a full page inside the placeholder instead of a bare spinner, so the raw HTML still says something useful.
Content behind a click (hx-trigger="click", which htmx's docs give as the default for every element except inputs, textareas, selects and forms) is the same problem in a stricter form: no crawler clicks. The tab, accordion and scroll patterns this affects are covered in lazy loaded content and crawlers.
Infinite scroll with revealed
The htmx infinite scroll example puts hx-get="/contacts/?page=2" and hx-trigger="revealed" on the last row, so each page loads the next as the user scrolls. A crawler gets page one. The good news is that the example already uses a real paginated URL. Expose it as a link too, so ?page=2 can be discovered and fetched as a full page:
Then make sure /contacts/?page=2 requested directly returns a complete page, not just table rows. The wider pagination rules are in pagination and infinite scroll for crawlers.
hx-push-url: every pushed URL must work as a full page
hx-push-url="true" pushes the fetched URL into the browser's history, so the address bar shows it and people can bookmark or share it. Boosted links and forms do the same by default. The hx-push-url reference also notes that the HX-Push-Url response header can override the attribute.
Once a URL is in the address bar, it will be requested directly: by someone opening a shared link, by a browser refresh, and by any crawler that finds the URL. htmx's history docs state the rule plainly: if you push a URL into the history, you must be able to navigate to that URL and get a full page back, because a user could paste it into an email or a new tab.
htmx also requests pushed URLs itself. On a history cache miss, its docs say it makes a request to the URL with the HX-History-Restore-Request header set to true and expects a full page in return.
The failure to look for is an endpoint built for swapping that returns a bare fragment on a direct visit:
html
<!-- Direct GET /guides/install/ returns only this -->
<section id="main">
<h2>Install the widget</h2>
<p>...</p>
</section>
No <title>, no <head>, no canonical, no navigation. A crawler that indexes this gets a page with no context and no links out.
Return a full document when HX-Request is absent
htmx sends HX-Request: true on its requests. Its docs say you need to check that header on the server to tell an htmx request from a regular one and decide what to render. A minimal version in Python with Flask:
python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.get("/guides/<slug>/")
def guide(slug):
data = load_guide(slug)
# Fragment for htmx swaps, full page for everyone else.
# History restores send HX-History-Restore-Request and expect a full page.
is_htmx = request.headers.get("HX-Request") == "true"
is_restore = request.headers.get("HX-History-Restore-Request") == "true"
if is_htmx and not is_restore:
template = "guide_fragment.html"
else:
template = "guide_page.html"
response = app.make_response(render_template(template, guide=data))
response.headers["Vary"] = "HX-Request"
return response
The restore check matters because of a default. At the time of writing, htmx's configuration reference lists htmx.config.historyRestoreAsHxRequest as defaulting to true, which means history-restore requests also carry HX-Request. The docs say to set it to false whenever you use HX-Request to return partial responses. With it set to false, the plain HX-Request check is enough; the restore check above is a safety net for the default.
The full template should include the fragment, so the content is identical in both cases and only the surrounding layout changes. That keeps you clear of serving crawlers something different from what users see.
Add Vary: HX-Request
When one URL can return two different bodies, a shared cache or CDN may store the fragment and hand it to the next visitor, including a crawler. htmx's docs say that if the server returns full HTML without the HX-Request header and fragments with it, "you need to add Vary: HX-Request", so the cache is keyed on the URL plus that header. If you cannot use Vary, the docs offer the getCacheBusterParam setting as an alternative: htmx then adds a cache-busting parameter to the GET requests it makes, so the browser does not store htmx and non-htmx responses in the same cache slot. Check separately that any CDN in front of the site keys on that parameter.
Fragment-only endpoints
Some endpoints exist only to be swapped in, such as /graph in the lazy-load example, and are never meant to be pages. Do not link them with href. If they can still be reached directly, either return a full page there or send X-Robots-Tag: noindex so a bare fragment does not end up indexed on its own.
List every hx-get with a load, revealed or intersect trigger. For each one, decide whether its content matters for search. If it does, it should be in the template.
Check every <a> that has hx-get. Each should also have an href, or sit inside a boosted container.
Request pushed URLs directly, without htmx headers. Each should return a full document with <title>, the main content and navigation:
The first count should be at least 1. The second can be 0 if you return fragments to htmx.
Check the response headers for Vary: HX-Request on any URL that returns both forms.
Comparing the raw response with what the browser shows after htmx has run is the same exercise described in raw vs rendered HTML.
Frequently asked questions
Is htmx bad for SEO?
No. htmx pages are usually rendered on the server, and boosted links are ordinary anchors. Problems come from specific patterns: content loaded on load, revealed or click, links without href, and pushed URLs that return fragments.
Do boosted links need any SEO changes?
Usually not in the markup, because the links and forms stay real. Check the server side: a direct request without the HX-Boosted and HX-Request headers must return the full page.
Can Googlebot see content loaded with hx-trigger="load"?
Googlebot renders JavaScript, so content fetched on load without any user action may appear after rendering; confirm it with URL Inspection. Crawlers that do not run JavaScript will see only the placeholder.
Should fragment endpoints be blocked in robots.txt?
Blocking them stops crawlers that render the page from fetching content it depends on. It is safer to keep important content out of fragment-only endpoints, and to return a full page or X-Robots-Tag: noindex when a fragment URL is requested directly.
Check what your htmx pages send
Start with the templates that use hx-trigger="load" or revealed for real content, and with any section that pushes URLs. The free check fetches one page, with no account, and shows whether its main text and links are in the raw HTML that crawlers receive.
Filed under Rendering and content. Topics: · htmx, javascript, html, rendering, internal-links
Check JavaScript navigation for real href destinations, direct route loading and usable source links so important pages are discoverable without clicks.
Do AI crawlers render JavaScript? Googlebot does. Most AI crawlers did not in Vercel's 2024 study. What that means for your pages and how to test them.