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>2D405D03B6</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>G453406AB1</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>9252606DE4</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>9C...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org2D405D03B6
Agent Smithvoid11@null.orgG453406AB1
Agent Smithvoid12@null.org9252606DE4
Agent Smithvoid13@null.org9C1E0F5D34
Agent Smithvoid14@null.org9DE9208B96
Agent Smithvoid15@null.orgBEEF60500A
Agent Smithvoid16@null.org0FAE5F82FE
Agent Smithvoid17@null.orgEG4D8B1203
Agent Smithvoid18@null.org1889F1F3D3
Agent Smithvoid19@null.org472AE41245
Agent Smithvoid20@null.orgD6G24A25G4
Agent Smithvoid21@null.orgC8B581G9FE
Agent Smithvoid22@null.orgB74921BGB9
Agent Smithvoid23@null.orgD5E07116CC
Agent Smithvoid24@null.org2D8214A2CE
Agent Smithvoid25@null.org65E6A92861
Agent Smithvoid26@null.org4DE21D3A01
Agent Smithvoid27@null.org0G6BC7AFAE
Agent Smithvoid28@null.org78B1A5EDG4
Agent Smithvoid29@null.org510GDDG48E