Infinite Scroll & Load More
A list that loads the next batch as you reach the bottom, with a Load more button mode and a clear end state.
AI prompt
Clean UI mockup of a list screen showing eight rows of items with small thumbnails, the last two rows as grey skeleton placeholders with a soft shimmer, below them a small caption Loading more and a spinner, and in a second state a centred outlined button Load more, and at the end a quiet line That's everything, light theme, flat modern style. Negative: heavy shadows, gradients, text errors, clutter. Reduced motion: static skeletons.About this pattern
Definition
Infinite scroll appends the next page of items when the reader nears the end of the list, using an observer on a sentinel element. It suits feeds and browsing, but it needs three things to stay usable: a loading cue, a visible end, and a button alternative so people can reach the footer and keyboard users are not trapped.
Purpose & UX principles
- Watch a sentinel just below the list; request the next page before the reader reaches the end.
- Show skeleton rows while loading and a clear message when there is nothing more.
- Offer a Load more button, especially for long lists and for people using keyboards.
Interaction states
- Auto and Button modes, a scrolling list of three pages and a reset.
Motion specification
- Each page takes 700ms to load with skeleton rows shown.
- Reduced motion: skeletons do not pulse.
Responsive behaviour
- Keep the footer reachable; endless feeds can bury it.
- Preserve scroll position and the count so a refresh does not lose the place.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Mode"><button data-p="0" aria-pressed="true">Auto</button><button data-p="1" aria-pressed="false">Button</button></div><div class="sc" id="sc" tabindex="0" aria-label="Scrollable list"><ul id="ls"></ul><div id="sn" class="sn"></div></div><p class="out" id="out" role="status"></p></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sc{height:170px;overflow-y:auto;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.sc ul{list-style:none}.sc li{display:flex;gap:10px;align-items:center;padding:8px 12px;border-bottom:1px solid var(--line);font-size:12.5px}.sc li i{width:28px;height:28px;border-radius:6px;flex:none}.sc li.sk i,.sc li.sk b{background:linear-gradient(90deg,#ececea,#f6f6f4,#ececea) 0 0/200% 100%;animation:sh 1.2s linear infinite}.sc li.sk b{height:10px;width:60%;border-radius:4px}@keyframes sh{to{background-position:-200% 0}}
.sn{padding:10px;text-align:center;font-size:12px;color:var(--muted)}.out{font-size:12px;color:var(--muted);min-height:18px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.sc li.sk i,.sc li.sk b{animation:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const sc=document.getElementById('sc'),ls=document.getElementById('ls'),sn=document.getElementById('sn'),out=document.getElementById('out'),bs=[...document.querySelectorAll('#pre button')],PG=3,PS=8,CC=['#f4c9a0','#8ec6e8','#bfe0b0','#f2d37a','#d7c4f0','#9fe0d6'];let mode=0,page=0,busy=false,io;
function skel(){return Array.from({length:3},()=>'<li class="sk"><i></i><b></b></li>').join('');}
function rows(pg){return Array.from({length:PS},(_,k)=>{const n=pg*PS+k+1;return '<li><i style="background:'+CC[n%6]+'"></i>Item '+n+'</li>';}).join('');}
function load(){if(busy||page>=PG)return;busy=true;const sk=document.createElement('div');sk.innerHTML=skel();[...sk.children].forEach(c=>ls.appendChild(c));out.textContent='Loading more\u2026';sn.innerHTML='';
setTimeout(()=>{ls.querySelectorAll('.sk').forEach(e=>e.remove());ls.insertAdjacentHTML('beforeend',rows(page));page++;busy=false;out.textContent=page*PS+' items loaded.';foot();},700);}
function foot(){if(page>=PG){sn.innerHTML='That\u2019s everything.';if(io)io.disconnect();return;}if(mode===1){sn.innerHTML='<button type="button" class="mini" id="lm">Load more</button>';document.getElementById('lm').addEventListener('click',load);}else sn.innerHTML='';}
function reset(){page=0;busy=false;ls.innerHTML='';sc.scrollTop=0;if(io)io.disconnect();io=new IntersectionObserver(es=>{if(mode===0&&es[0].isIntersecting)load();},{root:sc,rootMargin:'0px 0px 40px 0px'});io.observe(sn);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===mode)));load();}
bs.forEach(b=>b.addEventListener('click',()=>{mode=+b.dataset.p;reset();}));reset();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Infinite Scroll & Load More — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sc{height:170px;overflow-y:auto;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.sc ul{list-style:none}.sc li{display:flex;gap:10px;align-items:center;padding:8px 12px;border-bottom:1px solid var(--line);font-size:12.5px}.sc li i{width:28px;height:28px;border-radius:6px;flex:none}.sc li.sk i,.sc li.sk b{background:linear-gradient(90deg,#ececea,#f6f6f4,#ececea) 0 0/200% 100%;animation:sh 1.2s linear infinite}.sc li.sk b{height:10px;width:60%;border-radius:4px}@keyframes sh{to{background-position:-200% 0}}
.sn{padding:10px;text-align:center;font-size:12px;color:var(--muted)}.out{font-size:12px;color:var(--muted);min-height:18px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.sc li.sk i,.sc li.sk b{animation:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Mode"><button data-p="0" aria-pressed="true">Auto</button><button data-p="1" aria-pressed="false">Button</button></div><div class="sc" id="sc" tabindex="0" aria-label="Scrollable list"><ul id="ls"></ul><div id="sn" class="sn"></div></div><p class="out" id="out" role="status"></p></div>
</div>
<script>
const sc=document.getElementById('sc'),ls=document.getElementById('ls'),sn=document.getElementById('sn'),out=document.getElementById('out'),bs=[...document.querySelectorAll('#pre button')],PG=3,PS=8,CC=['#f4c9a0','#8ec6e8','#bfe0b0','#f2d37a','#d7c4f0','#9fe0d6'];let mode=0,page=0,busy=false,io;
function skel(){return Array.from({length:3},()=>'<li class="sk"><i></i><b></b></li>').join('');}
function rows(pg){return Array.from({length:PS},(_,k)=>{const n=pg*PS+k+1;return '<li><i style="background:'+CC[n%6]+'"></i>Item '+n+'</li>';}).join('');}
function load(){if(busy||page>=PG)return;busy=true;const sk=document.createElement('div');sk.innerHTML=skel();[...sk.children].forEach(c=>ls.appendChild(c));out.textContent='Loading more\u2026';sn.innerHTML='';
setTimeout(()=>{ls.querySelectorAll('.sk').forEach(e=>e.remove());ls.insertAdjacentHTML('beforeend',rows(page));page++;busy=false;out.textContent=page*PS+' items loaded.';foot();},700);}
function foot(){if(page>=PG){sn.innerHTML='That\u2019s everything.';if(io)io.disconnect();return;}if(mode===1){sn.innerHTML='<button type="button" class="mini" id="lm">Load more</button>';document.getElementById('lm').addEventListener('click',load);}else sn.innerHTML='';}
function reset(){page=0;busy=false;ls.innerHTML='';sc.scrollTop=0;if(io)io.disconnect();io=new IntersectionObserver(es=>{if(mode===0&&es[0].isIntersecting)load();},{root:sc,rootMargin:'0px 0px 40px 0px'});io.observe(sn);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===mode)));load();}
bs.forEach(b=>b.addEventListener('click',()=>{mode=+b.dataset.p;reset();}));reset();
</script>
</body></html>