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>DG6D819BDD</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>FBF1G63222</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>05GD945288</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>A3...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgDG6D819BDD
Agent Smithvoid11@null.orgFBF1G63222
Agent Smithvoid12@null.org05GD945288
Agent Smithvoid13@null.orgA3B407EGEC
Agent Smithvoid14@null.org8CAD8BBBAG
Agent Smithvoid15@null.orgG67D68D880
Agent Smithvoid16@null.orgBC1AC98FDF
Agent Smithvoid17@null.org75A5885E1G
Agent Smithvoid18@null.org3G7AFABD4G
Agent Smithvoid19@null.org27EB5F4FD3
Agent Smithvoid20@null.org9C68E848AE
Agent Smithvoid21@null.org05AA66GF8D
Agent Smithvoid22@null.orgCGE9AF5FAC
Agent Smithvoid23@null.org8E647D5F36
Agent Smithvoid24@null.orgGCCEB8954E
Agent Smithvoid25@null.orgC6B0FD6605
Agent Smithvoid26@null.org240C0BC407
Agent Smithvoid27@null.orgC6CD198FAD
Agent Smithvoid28@null.org066F47EDD2
Agent Smithvoid29@null.org10A82DC912