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>ACB0CF12BG</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>2E85AG5GG1</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>FDD08DCE64</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>CC...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgACB0CF12BG
Agent Smithvoid11@null.org2E85AG5GG1
Agent Smithvoid12@null.orgFDD08DCE64
Agent Smithvoid13@null.orgCCC68CF5CA
Agent Smithvoid14@null.org79E75D36BA
Agent Smithvoid15@null.orgD3A852A27B
Agent Smithvoid16@null.orgCBCGAC92D7
Agent Smithvoid17@null.orgB63D21E092
Agent Smithvoid18@null.org0F3BF3BCE4
Agent Smithvoid19@null.org9GC96D10G8
Agent Smithvoid20@null.orgE4C42E72A1
Agent Smithvoid21@null.org7E69CC7720
Agent Smithvoid22@null.org6AC670680A
Agent Smithvoid23@null.orgGF9CF32419
Agent Smithvoid24@null.org9F0197ADD6
Agent Smithvoid25@null.org0C0GGEEB45
Agent Smithvoid26@null.org49D3110A62
Agent Smithvoid27@null.org5649825CF1
Agent Smithvoid28@null.orgBGD43AAD05
Agent Smithvoid29@null.org8928280285