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>4F7B5BGFDB</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>A31G356GB4</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>493F30850F</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>E4...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org4F7B5BGFDB
Agent Smithvoid11@null.orgA31G356GB4
Agent Smithvoid12@null.org493F30850F
Agent Smithvoid13@null.orgE46AB3571C
Agent Smithvoid14@null.org0DD7C46D56
Agent Smithvoid15@null.orgC4EDD9BE8E
Agent Smithvoid16@null.org63029FC8BE
Agent Smithvoid17@null.orgF6506091FB
Agent Smithvoid18@null.org735330E83F
Agent Smithvoid19@null.org02D95FFF00
Agent Smithvoid20@null.org7B6F5C20F7
Agent Smithvoid21@null.orgC78GD4F2FF
Agent Smithvoid22@null.orgBD9134D890
Agent Smithvoid23@null.org38A679FG86
Agent Smithvoid24@null.org27A4FG3A28
Agent Smithvoid25@null.orgFBFGEGG5EG
Agent Smithvoid26@null.orgA3GC4F8293
Agent Smithvoid27@null.orgD46333A30C
Agent Smithvoid28@null.orgBB6D26EED3
Agent Smithvoid29@null.org9E4F448CCB
Loading...