Skip to content

Developer overview

A Molkit SVG export carries up to three layers that your page code can use. The theming layer puts every bond, atom label, and charge into stable .mk-* classes and includes a dark mode. The chemistry layer adds machine-readable data-mk-* attributes on the root, on every atom group, and on every bond group, plus an embedded MOL block, a 3D conformer, and dipole data. Animated exports add a third layer: a timeline that you can pause, scrub, and step through from plain JavaScript.

Molkit also provides a ready-made Molkit Viewer that reads the chemistry layer. This guide describes what the file format contains and the host-page code that uses it.

Layer How you get it What it adds Documented at
Theming The Theme-aware (light/dark) checkbox in the export dialog .mk-* classes and a scoped stylesheet, so you can restyle colors from your page; includes an automatic dark mode CSS theming
Chemistry metadata Always included in SVG exports from the Export SVG dialog data-mk-* attributes (formula, SMILES, per-atom and per-bond chemistry), an mk:chemistry metadata block, 3D conformers, and dipoles. An electrostatic potential map is added when the author made one Chemistry metadata
Animation Animated SVG export A timeline with data-duration, data-breakpoints, and data-transitions on the root. Molecule animations use SMIL; LaTeX solution animations use CSS @keyframes Control animated SVGs

In a theme-aware export, dark mode follows the operating system setting through a prefers-color-scheme media query inside the file. The file also has class hooks for sites with their own theme toggle: put mk-dark on the SVG or any ancestor to force dark, or mk-light to force light. SVGs exported before Molkit 0.19.0 may lack the class hooks and respond only to the media query; re-export them if you need the hooks.

How you put the file on the page decides what you can do with it. For the trade-offs, sizing, and pages with several copies of one export, see Embed SVG exports.

Method Animations Page CSS reaches inside Page JS reaches inside Use it for
<img src="mol.svg"> SMIL plays (no control) No, but the SVG’s own dark-mode media query still applies No Plain figures
<object data="mol.svg"> SMIL plays No Only through same-origin contentDocument access Self-running animations
<iframe src="mol.svg"> SMIL plays No Only through same-origin contentDocument access Isolated animations
Inline <svg> in the page SMIL plays Yes Yes Anything interactive; the recommended default

To read an export from your page, export it with Theme-aware (light/dark) checked, then paste the file’s contents into your page. Chemistry metadata is always included.

quickstart.html
<!doctype html>
<html lang="en">
<body>
<!-- Paste the full contents of your exported .svg file here. -->
<!-- Root shown abbreviated; a real export carries its styles inside. -->
<svg id="molkit-nknpn" viewBox="1866 1393 92 100" role="img"
data-mk-version="1.0" data-mk-formula="C6H6"
data-mk-smiles="c1ccccc1">
<style>/* exported .mk-* rules + dark-mode block live here */</style>
<!-- ...molecule geometry... -->
</svg>
<script>
const svg = document.querySelector('svg[data-mk-version]');
console.log(svg.dataset.mkFormula); // "C6H6"
</script>
</body>
</html>

Dark mode needs no code: the exported stylesheet follows the operating system setting. To force dark mode, add class="mk-dark" to the SVG or a parent.

Atoms and bonds carry data-mk-* attributes too. Atom groups carry data-mk-element, data-mk-hybridization, and the other per-atom attributes listed in Chemistry metadata. Bond groups carry data-mk-order, the endpoint atoms, and the bond style.

  • Embed SVG exports: inline, img, and object embedding, responsive sizing, several copies on one page, and resets for page CSS.
  • CSS theming: the .mk-* class reference, color overrides, class-based dark mode, and fonts.
  • Chemistry metadata: the data-mk-* schema, reading patterns and pitfalls, and extracting the MOL block.
  • Molkit Viewer: mounting the interactive viewer, the browser storage it uses, the dipole display, the 3D viewer, and electrostatic potential maps.
  • Control animated SVGs: the timeline attributes; pausing, scrubbing, and stepping; reduced motion; and how LaTeX solution exports differ.
  • Cookbook: copy-and-paste recipes for hover highlights, tooltips from metadata, scrubbers, and viewers.