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>D92D630F53</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>5551AFAD8G</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>169BAAAB50</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>1E...

🔗Demo

NameEmailID
Agent Smithvoid10@null.orgD92D630F53
Agent Smithvoid11@null.org5551AFAD8G
Agent Smithvoid12@null.org169BAAAB50
Agent Smithvoid13@null.org1EFEG31FE8
Agent Smithvoid14@null.org38369235E2
Agent Smithvoid15@null.org0960684CE9
Agent Smithvoid16@null.org8CC69DD60C
Agent Smithvoid17@null.orgC5F002C340
Agent Smithvoid18@null.org86CF2B57G7
Agent Smithvoid19@null.orgB7GG444A4E
Agent Smithvoid20@null.org2DE33C110C
Agent Smithvoid21@null.org8767DG4G29
Agent Smithvoid22@null.orgB9C85FBFF0
Agent Smithvoid23@null.org7GGCADD040
Agent Smithvoid24@null.org84CF12454B
Agent Smithvoid25@null.org7D88FBG5ED
Agent Smithvoid26@null.org3872G945AG
Agent Smithvoid27@null.org501EC1B175
Agent Smithvoid28@null.org8144D4409E
Agent Smithvoid29@null.org1319630ABG