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>07A4B0FEC2</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>726D94C703</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>AAD9AE592E</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>G0...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org07A4B0FEC2
Agent Smithvoid11@null.org726D94C703
Agent Smithvoid12@null.orgAAD9AE592E
Agent Smithvoid13@null.orgG072CGBA3E
Agent Smithvoid14@null.orgC637C79B21
Agent Smithvoid15@null.orgE8834331BD
Agent Smithvoid16@null.org4695BA9D97
Agent Smithvoid17@null.orgA32856E46F
Agent Smithvoid18@null.orgDDDFGD921A
Agent Smithvoid19@null.org1593GEADEC
Agent Smithvoid20@null.org18C44CB430
Agent Smithvoid21@null.orgA9A7D15141
Agent Smithvoid22@null.orgG70GD82EC5
Agent Smithvoid23@null.orgG62528CE5C
Agent Smithvoid24@null.orgFBE7F29E4F
Agent Smithvoid25@null.org04G91G8129
Agent Smithvoid26@null.orgFE33CC55FE
Agent Smithvoid27@null.org4DCBF90E18
Agent Smithvoid28@null.org65F6C3D1D5
Agent Smithvoid29@null.org7F0FCA74E1