Empty State with Action
A list that explains why it is empty and offers one clear action; add items to fill it and clear to see it again.
AI prompt
Create a task list component with a designed empty state. When empty: a simple line-art checklist icon, the heading "No tasks yet", the text "Add your first task to start planning your day." and a primary "Add task" button. After adding, tasks appear as rows with a checkbox and text; a small "Clear all" text button returns to the empty state. Light minimal style, rounded 12 pixel card, 1 pixel border, centred empty content, buttons at least 32 pixel tall. Announce additions with aria-live polite and keep focus on the Add button. Provide a prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.About this pattern
Definition
An empty state replaces a blank area when there is nothing to show yet. A good one says what belongs here, why it is empty and what to do next.
Purpose & UX principles
- First-run empties should teach: one line on the benefit, one primary action.
- Search or filter empties should say nothing matched and offer to clear the filter.
- Avoid humour that hides the instruction; keep the illustration light and decorative.
Interaction states
- Empty (message and action), populated (list with a Clear all action), and the transition between them.
Motion specification
- Items slide in 200ms; the empty message fades out 150ms.
- Reduced motion: items appear without sliding.
Responsive behaviour
- Centre the content in the container; keep the message under two lines and the button reachable with one thumb.
- Do not reserve large illustration space on small screens.
Code
<div class="bx"><div class="card"><div class="empty" id="em"><svg viewBox="0 0 48 48" width="40" height="40" aria-hidden="true" fill="none" stroke="#9a9a94" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="6" width="30" height="36" rx="4"/><path d="M16 16l3 3 5-6M16 28h16M16 35h10"/></svg><h2>No tasks yet</h2><p>Add your first task to start planning your day.</p></div><ul class="ls" id="ls" aria-live="polite"></ul></div>
<div class="act"><button id="add" type="button">Add task</button><button id="clr" type="button" hidden>Clear all</button></div></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}
.bx{width:min(300px,100%);display:grid;gap:10px;justify-items:center}
.card{width:100%;min-height:150px;border-radius:12px;background:var(--surface);border:1px solid var(--line);padding:10px;display:grid;align-content:center}
.empty{text-align:center;display:grid;justify-items:center;gap:4px;padding:14px}.empty h2{font-size:15px}.empty p{font-size:12.5px;color:var(--muted)}
.empty[hidden]{display:none}
.ls{list-style:none;padding:0;display:grid;gap:4px}
.ls li{display:flex;gap:8px;align-items:center;padding:8px 10px;border-radius:8px;background:var(--surface-2);font-size:13px;animation:in .2s ease-out}
@keyframes in{from{opacity:0;transform:translateY(6px)}}
.ls input{accent-color:#171717}
.act{display:flex;gap:6px}.act button{height:32px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12.5px;cursor:pointer}
#add{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-weight:600}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.ls li{animation:none}}const T=['Reply to Sam','Book dentist','Water plants','Plan Friday','Pay rent'],ls=document.getElementById('ls'),em=document.getElementById('em'),clr=document.getElementById('clr');let n=0;
function sync(){em.hidden=ls.children.length>0;clr.hidden=ls.children.length===0;}
document.getElementById('add').addEventListener('click',()=>{const li=document.createElement('li');li.innerHTML='<input type="checkbox" aria-label="Done"><span></span>';li.lastChild.textContent=T[n++%T.length];ls.append(li);sync();});
clr.addEventListener('click',()=>{ls.innerHTML='';sync();});sync();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>Empty State with Action — 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}}
.bx{width:min(300px,100%);display:grid;gap:10px;justify-items:center}
.card{width:100%;min-height:150px;border-radius:12px;background:var(--surface);border:1px solid var(--line);padding:10px;display:grid;align-content:center}
.empty{text-align:center;display:grid;justify-items:center;gap:4px;padding:14px}.empty h2{font-size:15px}.empty p{font-size:12.5px;color:var(--muted)}
.empty[hidden]{display:none}
.ls{list-style:none;padding:0;display:grid;gap:4px}
.ls li{display:flex;gap:8px;align-items:center;padding:8px 10px;border-radius:8px;background:var(--surface-2);font-size:13px;animation:in .2s ease-out}
@keyframes in{from{opacity:0;transform:translateY(6px)}}
.ls input{accent-color:#171717}
.act{display:flex;gap:6px}.act button{height:32px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12.5px;cursor:pointer}
#add{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-weight:600}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.ls li{animation:none}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="card"><div class="empty" id="em"><svg viewBox="0 0 48 48" width="40" height="40" aria-hidden="true" fill="none" stroke="#9a9a94" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="6" width="30" height="36" rx="4"/><path d="M16 16l3 3 5-6M16 28h16M16 35h10"/></svg><h2>No tasks yet</h2><p>Add your first task to start planning your day.</p></div><ul class="ls" id="ls" aria-live="polite"></ul></div>
<div class="act"><button id="add" type="button">Add task</button><button id="clr" type="button" hidden>Clear all</button></div></div>
</div>
<script>
const T=['Reply to Sam','Book dentist','Water plants','Plan Friday','Pay rent'],ls=document.getElementById('ls'),em=document.getElementById('em'),clr=document.getElementById('clr');let n=0;
function sync(){em.hidden=ls.children.length>0;clr.hidden=ls.children.length===0;}
document.getElementById('add').addEventListener('click',()=>{const li=document.createElement('li');li.innerHTML='<input type="checkbox" aria-label="Done"><span></span>';li.lastChild.textContent=T[n++%T.length];ls.append(li);sync();});
clr.addEventListener('click',()=>{ls.innerHTML='';sync();});sync();
</script>
</body></html>