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>EE03AD12AA</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>C17DGG41DD</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>A3AE10ED3D</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>DE...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgEE03AD12AA
Agent Smithvoid11@null.orgC17DGG41DD
Agent Smithvoid12@null.orgA3AE10ED3D
Agent Smithvoid13@null.orgDE0GBE43G9
Agent Smithvoid14@null.orgGA808BC2D9
Agent Smithvoid15@null.orgF8B6C4CC0G
Agent Smithvoid16@null.orgA98D2A37BD
Agent Smithvoid17@null.orgGCA78GFE9G
Agent Smithvoid18@null.orgG53321F66E
Agent Smithvoid19@null.org0C3A5FGFGC
Agent Smithvoid20@null.org51B9BF0CBE
Agent Smithvoid21@null.org002B4ADE2G
Agent Smithvoid22@null.org91B272CCA1
Agent Smithvoid23@null.org7D315EDBC9
Agent Smithvoid24@null.org62BB3CE090
Agent Smithvoid25@null.org1734230DGE
Agent Smithvoid26@null.orgBG3D9AAA3G
Agent Smithvoid27@null.orgGA69362921
Agent Smithvoid28@null.org35DD13DC6A
Agent Smithvoid29@null.org15GCGB2B76