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>939FAG837B</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>90478E6806</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>29BBCFE824</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>D8...

🔗Demo

NameEmailID
Agent Smithvoid10@null.org939FAG837B
Agent Smithvoid11@null.org90478E6806
Agent Smithvoid12@null.org29BBCFE824
Agent Smithvoid13@null.orgD87G35908C
Agent Smithvoid14@null.orgF649A42426
Agent Smithvoid15@null.orgE51D336E89
Agent Smithvoid16@null.org473BB9E84D
Agent Smithvoid17@null.org3G817FDEG8
Agent Smithvoid18@null.org36CCG899FB
Agent Smithvoid19@null.orgC1B8G3F8AE
Agent Smithvoid20@null.org58GC135B0D
Agent Smithvoid21@null.orgF4E3DFCF29
Agent Smithvoid22@null.org570631C26B
Agent Smithvoid23@null.org41G204FE06
Agent Smithvoid24@null.org4D6DG0G761
Agent Smithvoid25@null.org6A061AEGF3
Agent Smithvoid26@null.orgFC61FFBD4D
Agent Smithvoid27@null.org5C4361G440
Agent Smithvoid28@null.org288GAC3A7C
Agent Smithvoid29@null.org27343B1060