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>AD79EGF555</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>9E2G9F3F53</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>9C05C7A88A</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>77...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgAD79EGF555
Agent Smithvoid11@null.org9E2G9F3F53
Agent Smithvoid12@null.org9C05C7A88A
Agent Smithvoid13@null.org77FA7E0755
Agent Smithvoid14@null.org02D94D9G2C
Agent Smithvoid15@null.orgGBDFE3F717
Agent Smithvoid16@null.org6G7EGG07F7
Agent Smithvoid17@null.org1DE2C0817A
Agent Smithvoid18@null.orgCB61G9792F
Agent Smithvoid19@null.org9D37798073
Agent Smithvoid20@null.orgDF3944A516
Agent Smithvoid21@null.org10A5G6B109
Agent Smithvoid22@null.org037A180ACD
Agent Smithvoid23@null.org8A5B83A455
Agent Smithvoid24@null.org8487GF2A01
Agent Smithvoid25@null.org67FD86F90F
Agent Smithvoid26@null.orgCEE88FA17F
Agent Smithvoid27@null.org98141DG1C4
Agent Smithvoid28@null.org681546EA79
Agent Smithvoid29@null.org3F38C0AE2A