Interactive study flashcards
A keyboard-friendly single-file flashcard deck with flip animations and progress tracking.
Source code
1 lines · 1.9 KB<style>*{box-sizing:border-box}body{margin:0;font-family:Inter,system-ui,sans-serif;background:#f6f7fb;color:#172033}button,a{font:inherit}.wrap{width:min(960px,calc(100% - 32px));margin:auto}</style><style>main{min-height:100vh;display:grid;place-items:center;padding:24px}.deck{width:min(480px,100%);text-align:center}.card{background:#fff;border:1px solid #dfe3ec;border-radius:20px;padding:36px 28px;min-height:220px;display:grid;place-items:center;cursor:pointer;box-shadow:0 16px 40px #1e293b10}.q{font-size:22px;font-weight:700}.a{font-size:17px;color:#0f766e;line-height:1.6}.controls{display:flex;justify-content:space-between;align-items:center;margin-top:16px}.controls button{padding:10px 18px;border-radius:10px;border:1px solid #cfd5e2;background:#fff;cursor:pointer;font-weight:600}</style><main><div class="deck"><p id="prog">Card 1 of 3</p><div class="card" tabindex="0" onclick="flip()" onkeydown="if(event.key==='Enter'||event.key===' ')flip()"><div id="face" class="q"></div></div><div class="controls"><button onclick="step(-1)">Prev</button><button onclick="flip()">Flip</button><button onclick="step(1)">Next</button></div></div></main><script>const cards=[{q:"What does CSS clamp(min, pref, max) do?",a:"It keeps a value responsive between a minimum and maximum bound without media queries."},{q:"Why omit allow-same-origin on untrusted iframes?",a:"It assigns an opaque origin so scripts cannot access parent cookies or storage."},{q:"What makes a single-file demo easy to review?",a:"Self-contained HTML/CSS/JS with deterministic sample data."}];let i=0,shown=false;function render(){const f=document.getElementById("face");f.className=shown?"a":"q";f.textContent=shown?cards[i].a:cards[i].q;document.getElementById("prog").textContent="Card "+(i+1)+" of "+cards.length}function flip(){shown=!shown;render()}function step(d){i=(i+d+cards.length)%cards.length;shown=false;render()}render()</script>When this template fits
Use this single-file flashcard deck for language vocabulary, exam review, interview prep, or classroom warm-ups where learners benefit from active recall without installing an app.
How the layout works
A centered card holds either the prompt or the answer face, paired with a progress indicator and Previous / Flip / Next controls. Keyboard Enter and Space keys flip the card directly.
What to customize
Edit the cards array in the inline script with your own question-and-answer pairs, add category tags if splitting topics, and adjust font size for longer explanations.
Review before publishing
Check keyboard tab order across the card and buttons, verify long answers wrap cleanly at 390px, and keep each card concise enough to read without scrolling.
Keep building with context
Compare a related pattern or read a practical guide before adapting this example in the Playground.