One quiz question to answer: pick one, pick many, true or false, or type it. Keys 1 to 9 pick, Enter checks, and the verdict and explanation open below.
On this page
Used for
- A quiz question
- A knowledge check in a lesson
- A poll with a right answer
- A flashcard that checks typing
Examples
Multiple choice with partial credit
True or false, and a typed answer
Reveal at the end
Installation
npx knowns-ui@latest add question-cardFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Question Card from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/question-card
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add question-card
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- lib/knowns/quiz.ts
- lib/knowns/quiz-glyphs.tsx
- components/ui/knowns/question-card/question-card.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/question-card, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "question-card" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- questionrequired
QuizQuestion- { id, kind, prompt, choices?, answer, explanation?, points?, timeLimitSec? } from lib/knowns/quiz. kind is single, multi, truefalse or short.
- value / defaultValue / onValueChange
string[]- Default
[] - The picked choice ids, or the typed text as the first item for a short question.
- submitted / defaultSubmitted
boolean- Default
false - Whether the answer is handed in. It locks the card. Controlled for a review screen.
- onSubmit
(value, grade) => void- Called when the answer is handed in. grade has correct, fraction, points, max, hits, extras and misses.
- reveal
boolean- Default
true - Show right and wrong after submitting. false locks the answer with no verdict, for a quiz that reveals at the end.
- number
number- Shows Question 3 above the prompt.
- showKeys / submitLabel
boolean / string- Default
true / Check answer - The 1 to 9 key on each choice, and the button text.
- actions
ReactNode- Extra content next to the submit button, such as a Next button.
- autoFocus / disabled
boolean- Default
false - Focus the first control on mount; or lock everything.
- Keyboard
keys- 1 to 9 pick a choice (T and F for true or false), Enter checks the answer, the arrow keys and Space work as on real radio buttons and checkboxes. In the text box of a short question digits are typed.
- Screen readers
live region- Right and wrong are announced as Correct, Partly right or Not quite, with the right answer. A wrong or missed choice also says so in its own label.
- Motion
180ms ease-out- The verdict folds open once; choice colours change in 120ms. Nothing plays on first render or with reduced motion.
| Prop | Type | Default | Description |
|---|---|---|---|
| questionrequired | QuizQuestion | required | { id, kind, prompt, choices?, answer, explanation?, points?, timeLimitSec? } from lib/knowns/quiz. kind is single, multi, truefalse or short. |
| value / defaultValue / onValueChange | string[] | [] | The picked choice ids, or the typed text as the first item for a short question. |
| submitted / defaultSubmitted | boolean | false | Whether the answer is handed in. It locks the card. Controlled for a review screen. |
| onSubmit | (value, grade) => void | - | Called when the answer is handed in. grade has correct, fraction, points, max, hits, extras and misses. |
| reveal | boolean | true | Show right and wrong after submitting. false locks the answer with no verdict, for a quiz that reveals at the end. |
| number | number | - | Shows Question 3 above the prompt. |
| showKeys / submitLabel | boolean / string | true / Check answer | The 1 to 9 key on each choice, and the button text. |
| actions | ReactNode | - | Extra content next to the submit button, such as a Next button. |
| autoFocus / disabled | boolean | false | Focus the first control on mount; or lock everything. |
| Keyboard | keys | - | 1 to 9 pick a choice (T and F for true or false), Enter checks the answer, the arrow keys and Space work as on real radio buttons and checkboxes. In the text box of a short question digits are typed. |
| Screen readers | live region | - | Right and wrong are announced as Correct, Partly right or Not quite, with the right answer. A wrong or missed choice also says so in its own label. |
| Motion | 180ms ease-out | - | The verdict folds open once; choice colours change in 120ms. Nothing plays on first render or with reduced motion. |
What it handles
- 01Renders single choice, multiple choice, true or false and a typed answer from one question object.
- 02Picks with the keys 1 to 9 (T and F for true or false), hands the answer in with Enter, and keeps the arrow keys and Space of real radio buttons and checkboxes.
- 03Grades with partial credit for multiple choice and shows the right answer, the points and your explanation in a verdict that opens below.
- 04Marks right and wrong with a glyph as well as colour, and says Correct or Not quite and the right answer through a polite live region.
- 05Locks after the answer is handed in, or locks without a verdict when the quiz reveals at the end.
- 06Works controlled for a review screen: pass the saved value and submitted, and it shows the verdict with no controls.
States
- Pick
- The choice takes the selected border and fill
- 120ms, ease-out
- Check answer
- The verdict and explanation fold open
- 180ms, ease-out
- Right or wrong
- Green or red border and a check or cross
- 120ms, ease-out
- First render
- Nothing plays
- none
- Reduced motion
- The verdict appears at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| Pick | The choice takes the selected border and fill | 120ms, ease-out |
| Check answer | The verdict and explanation fold open | 180ms, ease-out |
| Right or wrong | Green or red border and a check or cross | 120ms, ease-out |
| First render | Nothing plays | none |
| Reduced motion | The verdict appears at once | 0ms |
Works with
When to use
When to use
- One question in a lesson or a knowledge check, where the person answers and sees at once if they were right and why.
- A true or false, multiple choice or typed question you build the page around yourself.
When not to use
- Running a whole quiz with progress, a timer and a score: use Quiz Player.
- A choice with no right answer, such as a setting: use Radio Group.
- Writing the questions: use Quiz Builder.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Question Card to my app and wire it to my own data.
- I need one question in a lesson or a knowledge check, where the person answers and sees at once if they were right and why. Set that up with the Knowns UI Question Card.
- Which Question Card props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "question-card" }) and search_docs({ query: "question card" }).