Infinite Scroll

The infinite scroll pattern provides a way to load content dynamically on user scrolling action.

Let’s focus on the final row (or the last element of your content):

<tr hx-get="/contacts/?page=2"
    hx-trigger="revealed"
    hx-swap="afterend">
  <td>Agent Smith</td>
  <td>void29@null.org</td>
  <td>55F49448C0</td>
</tr>

This last element contains a listener which, when scrolled into view, will trigger a request. The result is then appended after it. The last element of the results will itself contain the listener to load the next page of results, and so on.

revealed - triggered when an element is scrolled into the viewport (also useful for lazy-loading). If you are using overflow in css like overflow-y: scroll you should use intersect once instead of revealed.

Server Requests ↑ Show
HTML
<table hx-indicator=".htmx-indicator"><thead><tr><th>Name</th><th>Email</th><th>ID</th></tr></thead><tbody>
              <tr><td>Agent Smith</td><td>void10@null.org</td><td>4G061G6241</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>C27042FCFE</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>G52E096978</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>E5...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org4G061G6241
Agent Smithvoid11@null.orgC27042FCFE
Agent Smithvoid12@null.orgG52E096978
Agent Smithvoid13@null.orgE5C0987723
Agent Smithvoid14@null.orgCCA97D07B2
Agent Smithvoid15@null.org1C5FD0A355
Agent Smithvoid16@null.orgE15A9FD329
Agent Smithvoid17@null.org7094183E73
Agent Smithvoid18@null.org2E0B90C281
Agent Smithvoid19@null.org627C06B2F2
Agent Smithvoid20@null.orgB5EEBF08D9
Agent Smithvoid21@null.org95BG78A708
Agent Smithvoid22@null.orgABF53GB25C
Agent Smithvoid23@null.orgA0562D9F54
Agent Smithvoid24@null.org42D2A3F1AA
Agent Smithvoid25@null.org34EFF6E7C8
Agent Smithvoid26@null.org8F84306EG5
Agent Smithvoid27@null.orgG9GG4G1271
Agent Smithvoid28@null.org0FE7CAGBC9
Agent Smithvoid29@null.orgDF5ADDB13B
Loading...