Embed practice problems
The Molkit practice editor is a small drawing editor that sits in an iframe on your page. It shows one problem, the student draws an answer, and Check sends the drawing to Molkit to be graded. The student sees feedback in the editor, and a correct answer shows a check code. Problems come from Molkit’s problem list.

Add a problem to a page
Section titled “Add a problem to a page”-
Pick a problem id from the problem list, for example
water-lewis-1. -
Paste this where the editor should appear:
<div class="molkit-practice" data-problem="water-lewis-1"></div><script src="https://molkit.com/practice/loader.js" defer></script> -
Publish the page. The loader turns the
divinto an iframe that is as wide as its container and 520 px tall.
You need the script tag once per page. Every div with the class molkit-practice on the page becomes its own editor, so one page can hold several problems.
Snippet options
Section titled “Snippet options”Add these attributes to the div. Only data-problem is required.
Problem and drawing
Section titled “Problem and drawing”| Attribute | Values | Default | What it does |
|---|---|---|---|
data-problem |
a problem id | none | The problem to load. |
data-prompt |
text, up to 500 characters | the problem’s own prompt | Replaces the prompt shown above the canvas. Write formulas with _ for a subscript and ^ for a charge: NO_2^- shows NO2−. |
data-tools |
a comma-separated list of bond, charge, lp, radical, and eraser |
the problem’s own list | The drawing tools the student gets. charge gives both the positive and the negative charge tool. Select, Pan, Click to bond, and Ion brackets are always shown. |
data-elements |
a comma-separated list of element symbols, such as C,O |
the problem’s own list | The element buttons the student gets. H is added when the student draws every hydrogen, as every problem in the list asks. The editor has buttons for H, C, N, O, S, P, F, Cl, Br, and I. |
data-h |
explicit or implicit |
explicit |
Whether the student draws every hydrogen. Used only when the problem’s settings cannot be loaded; the problem’s own setting applies otherwise. |
data-attempts |
a whole number from 0 to 20; 0 means no limit | 3 | How many attempts the student gets. Used only when the problem’s settings cannot be loaded; the problem’s own count applies otherwise. |
Look and layout
Section titled “Look and layout”| Attribute | Values | Default | What it does |
|---|---|---|---|
data-theme |
light or dark |
light |
The editor’s colors. The editor never follows the visitor’s system setting or your page’s colors; it changes only when you ask. |
data-accent |
blue, green, teal, indigo, purple, rose, graphite, burnt-orange, harvest-gold, or custom:#rrggbb |
blue |
The color of the active tool, the Check button, and the selection. An unknown value is ignored. |
data-height |
a length such as 600, 600px, 40rem, or 70vh |
520px, growing with the feedback |
A fixed height for the iframe. A bare number is read as pixels. Without it, the iframe grows when the feedback opens (up to 2,000 px) and shrinks back when it closes. |
data-lazy |
true |
off | Shows a card with the prompt and a Practice: draw it yourself button instead of the editor. The editor loads when the student clicks the button. Use it on long pages with many problems. |
data-preview |
a picture URL starting with https://, //, or / |
none | With data-lazy, a picture shown on the card. |
Feedback
Section titled “Feedback”| Attribute | Values | Default | What it does |
|---|---|---|---|
data-code |
off |
on | off hides the check code after a correct answer. Use it where no teacher collects codes, such as a product page. |
data-net |
on |
off | Shows a Net charge line next to the prompt, worked out from the electrons drawn so far. It is off by default because it counts the electrons for the student. |
data-show-result |
true |
off | Prints the result of each check under the editor as JSON. Use it while you build a page; students do not need it. |
An example with several options:
<div class="molkit-practice" data-problem="nitrite-lewis-1" data-tools="bond,charge,lp,eraser" data-elements="N,O" data-theme="light" data-accent="burnt-orange" data-height="600"></div><script src="https://molkit.com/practice/loader.js" defer></script>Embed in a learning management system
Section titled “Embed in a learning management system”Many learning management systems remove script tags from course pages. In that case, use a plain iframe that points at the editor:
<iframe src="https://molkit.com/practice/practice.html?p=water-lewis-1" width="100%" height="560" title="Molkit practice" allow="clipboard-write"></iframe>In Canvas, paste it in the HTML editor of a page, or of a New Quizzes stimulus or essay item. The options from the tables above work as URL parameters with the same names, without data-: &accent=burnt-orange&code=off. The exceptions are data-height, data-lazy, data-preview, and data-show-result, which belong to the loader; set the height on the iframe itself.
A plain iframe does not grow when the feedback opens, so give it a height with room for the feedback, about 560 px or more.
Check codes
Section titled “Check codes”When a student’s answer is correct, the editor shows Check code: followed by five letters and digits. The code is the same for every student who answers that problem correctly, so it shows that the student reached a correct drawing.
To collect check codes:
- Answer the problem yourself in the editor and note the code it shows.
- Add a question next to the problem that asks for the check code, such as a fill-in-the-blank quiz item.
- Use the code from step 1 as the correct answer.
A check code records that the student got the drawing right, not that they did it alone. Reloading the page gives a fresh set of attempts, and students can share codes. Use codes for practice credit, not for graded tests.
JavaScript API
Section titled “JavaScript API”The loader adds a MolkitPractice object to your page. Each function takes the editor’s index on the page (0 for the first) and sends a message to that editor.
| Call | What it does |
|---|---|
MolkitPractice.setTheme(i, 'dark') |
Switches editor i to 'dark' or 'light'. |
MolkitPractice.setAccent(i, 'teal') |
Sets the accent color. Takes the same values as data-accent; an unknown value is ignored. |
MolkitPractice.setProblem(i, 'co2-lewis-1') |
Loads another problem and clears the drawing. |
MolkitPractice.check(i) |
Checks the drawing, as the Check button does. |
MolkitPractice.reset(i) |
Clears the drawing, as the Reset button does. |
MolkitPractice.getSubmission(i) |
Asks for the drawing as a Molkit file; it arrives as an mk:submission event. |
MolkitPractice.scan() |
Wires up molkit-practice elements added to the page after it loaded. |
MolkitPractice.instances lists the editors on the page; instances[i].last holds the last message from editor i.
To follow a theme switch on your page:
document.querySelector('#dark-toggle').addEventListener('change', (e) => { MolkitPractice.setTheme(0, e.target.checked ? 'dark' : 'light');});Events
Section titled “Events”Each editor sends a molkit-practice event to its div. The event bubbles, and event.detail.type says what happened.
detail.type |
When |
|---|---|
mk:ready |
The editor has started. |
mk:problem-loaded |
A problem is loaded. detail.problemId names it. |
mk:drawing-changed |
The drawing changed. detail.atoms and detail.bonds give the counts. |
mk:check-result |
A check finished. detail.verdict is correct, incorrect, uncertain, or too-small; detail.attempt, detail.attemptsLeft, and detail.findings (the feedback lines) come with it, and detail.code on a correct answer. |
mk:answer-shown |
The student asked to see the answer after the last attempt. |
mk:submission |
The reply to getSubmission. detail.mkit holds the drawing. |
mk:error |
A check could not run, or no attempts are left. detail.code and detail.message say why. |
mk:resize |
The editor asked for a new height. |
document.addEventListener('molkit-practice', (e) => { if (e.detail.type === 'mk:check-result') { console.log(e.detail.problemId, e.detail.verdict); }});The events and instances[i].last live in the student’s browser, and a student can fake them from the developer console. Use them to update your page, never to record a grade.
Limits
Section titled “Limits”- Problems come from Molkit’s problem list. You cannot add your own problems.
- Grading needs a connection to molkit.com. When it cannot be reached, Check says checking is unavailable and does not use up an attempt.
- Each problem is checked at most once every 4 seconds per student. A quicker second check waits and then runs.
- The editor needs a browser that runs JavaScript. It works at phone width, but drawing is easier with a mouse or a stylus.
- The editor does not save the drawing. Reloading the page clears it and gives a fresh set of attempts.
For what the student sees, see Answer a practice problem.