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>DG9E28E8AE</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>BF01GACFEC</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>8A3C946D78</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>F1...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgDG9E28E8AE
Agent Smithvoid11@null.orgBF01GACFEC
Agent Smithvoid12@null.org8A3C946D78
Agent Smithvoid13@null.orgF18GA8C894
Agent Smithvoid14@null.orgA1D65BDCD9
Agent Smithvoid15@null.org5B2FB31E62
Agent Smithvoid16@null.org7GE6E1673B
Agent Smithvoid17@null.org95C9A7GAGF
Agent Smithvoid18@null.org1AED5CE9A7
Agent Smithvoid19@null.orgG25D3FAFF7
Agent Smithvoid20@null.org515B052571
Agent Smithvoid21@null.org3C6A7373F2
Agent Smithvoid22@null.org273643F199
Agent Smithvoid23@null.org9GBGFA4F72
Agent Smithvoid24@null.orgA052BADFB4
Agent Smithvoid25@null.org94386A83D5
Agent Smithvoid26@null.orgG3BE4FGB51
Agent Smithvoid27@null.org3D445AC2C9
Agent Smithvoid28@null.orgG64A730E80
Agent Smithvoid29@null.org2G2EF3B86C