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>FGC94F33D6</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>E2E82DB7DB</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>DB0325BB31</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>CA...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgFGC94F33D6
Agent Smithvoid11@null.orgE2E82DB7DB
Agent Smithvoid12@null.orgDB0325BB31
Agent Smithvoid13@null.orgCAG02G0523
Agent Smithvoid14@null.org10GF1A834B
Agent Smithvoid15@null.org8ECD9A61B8
Agent Smithvoid16@null.orgAGG155CFD8
Agent Smithvoid17@null.orgB3E910F409
Agent Smithvoid18@null.org9BF36G40GA
Agent Smithvoid19@null.org8F74C89BG1
Agent Smithvoid20@null.org41C29GE547
Agent Smithvoid21@null.org0C08CD65CF
Agent Smithvoid22@null.org84D4B838F0
Agent Smithvoid23@null.orgED2A30B573
Agent Smithvoid24@null.orgEE231F7GEF
Agent Smithvoid25@null.org9F46AG91B1
Agent Smithvoid26@null.org9AD5F66925
Agent Smithvoid27@null.orgD6D21294C9
Agent Smithvoid28@null.orgC59CA8788E
Agent Smithvoid29@null.org73D138F5A6