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>763B17854E</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>65399F08F3</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>EDA556BG76</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>B5...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org763B17854E
Agent Smithvoid11@null.org65399F08F3
Agent Smithvoid12@null.orgEDA556BG76
Agent Smithvoid13@null.orgB5AG209DC6
Agent Smithvoid14@null.org0AE5C68200
Agent Smithvoid15@null.org9EA1CCA614
Agent Smithvoid16@null.org57D3352E94
Agent Smithvoid17@null.orgE409552E05
Agent Smithvoid18@null.orgGEA6E44FC8
Agent Smithvoid19@null.orgDBG2GF3712
Agent Smithvoid20@null.orgD7F4DC9CDD
Agent Smithvoid21@null.org49E9A41175
Agent Smithvoid22@null.org0E9C2024D1
Agent Smithvoid23@null.org1B50394136
Agent Smithvoid24@null.orgB24D983A55
Agent Smithvoid25@null.org36FCAG5ACF
Agent Smithvoid26@null.orgD15CF237GA
Agent Smithvoid27@null.orgGFB1760EA8
Agent Smithvoid28@null.orgBGB073C4E4
Agent Smithvoid29@null.orgG915170F7C