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>8831GB8BAA</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>33F5CDD1GG</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>F67G8E5F6C</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>B9...

πŸ”—Demo

NameEmailID
Agent Smithvoid10@null.org8831GB8BAA
Agent Smithvoid11@null.org33F5CDD1GG
Agent Smithvoid12@null.orgF67G8E5F6C
Agent Smithvoid13@null.orgB9G36AC213
Agent Smithvoid14@null.org8C47A38256
Agent Smithvoid15@null.org94GF3A1844
Agent Smithvoid16@null.org9D9A72D54B
Agent Smithvoid17@null.org2E63EAE310
Agent Smithvoid18@null.org3CC5742E41
Agent Smithvoid19@null.org0C82978B28
Agent Smithvoid20@null.org01GF4BD088
Agent Smithvoid21@null.orgA893GD7C2C
Agent Smithvoid22@null.orgB3EGD4C333
Agent Smithvoid23@null.org2E051C1EA2
Agent Smithvoid24@null.orgEFE116DE1C
Agent Smithvoid25@null.orgCDDF8C61F7
Agent Smithvoid26@null.org1E76332AC9
Agent Smithvoid27@null.orgD9B45678GD
Agent Smithvoid28@null.org8FD72A9E2B
Agent Smithvoid29@null.orgB83787AFGB