SmarkForm

SmarkForm turns annotated HTML into a component tree whose fields, nested forms, and lists import and export structured JavaScript objects and arrays.

NPM Version npm dependencies NPM Downloads jsDelivr Hits License

πŸ”‡ Autoplays muted β€” unmute it (πŸ”Š in the player controls) to hear the narration.

How SmarkForm works

Keep your HTML and CSS. Add data-smark to the elements SmarkForm should manage, then initialize the root:

<div id="profile">
  <input data-smark name="name" value="Ada">

  <fieldset data-smark='{"type":"form","name":"address"}'>
    <input data-smark name="city" value="Barcelona">
  </fieldset>

  <ul data-smark='{"type":"list","name":"phones"}'>
    <li><input data-smark name="number" value="+34 600 000 000"></li>
  </ul>
</div>

<script>
  new SmarkForm(document.getElementById("profile"));
</script>

That markup describes a component tree. Exporting the root returns ordinary structured data:

{
  "name": "Ada",
  "address": { "city": "Barcelona" },
  "phones": [{ "number": "+34 600 000 000" }]
}

Named fields become object properties, each list item template becomes an array element, and forms and lists can nest to any depth. SmarkForm does not render a schema or take over your application: you still own the markup, styles, semantics, validation, and submission policy.

Animated diagram: every SmarkForm component is a field. Forms return objects, lists return arrays, and value fields return individual JSON values. Forms and lists can nest to any depth.
Forms and lists are fields too, so they compose into nested JSON.

Try the interactive demo

A nested subform, a sortable list, context-driven hotkeys, and date/time coercion β€” all driven by data-smark attributes. Switch between the HTML, CSS, JavaScript, and preview tabs, then export the result as JSON.

πŸ”—
❓
<div id="myForm">
  <div class="ep">
    <p>
      <label data-smark>πŸ“‹ Event:</label>
      <input data-smark name="title" type="text" placeholder="e.g. Sprint Review">
    </p>
    <p>
      <label data-smark>πŸ“… Date:</label>
      <input data-smark name="date" type="date">
    </p>
    <p>
      <label data-smark>⏰ Time:</label>
      <input data-smark name="time" type="time">
    </p>
    <fieldset data-smark='{"type":"form","name":"organizer"}'>
      <legend data-smark='label'>πŸ‘€ Organizer</legend>
      <p>
        <label data-smark>Name:</label>
        <input data-smark name="name" type="text">
      </p>
      <p>
        <label data-smark>Email:</label>
        <input data-smark name="email" type="email">
      </p>
    </fieldset>
    <div class="ep-list">
      <button data-smark='{"action":"removeItem","context":"attendees","hotkey":"Delete","preserve_non_empty":true}' title='Remove empty slots'>🧹</button>
      <button data-smark='{"action":"addItem","context":"attendees","hotkey":"+"}' title='Add attendee'>βž•</button>
      <strong data-smark='label'>πŸ‘₯ Attendees:</strong>
      <ul data-smark='{"type":"list","name":"attendees","sortable":true,"export_empties":false}'>
        <li>
          <details>
            <summary>
              <span data-smark-type="label" class="bullet">
                <span data-smark-action="position">N</span> ☰
              </span>
              <input data-smark type="text" name="name" placeholder="Name">
              <button data-smark='{"action":"removeItem","hotkey":"-"}' title='Remove'>βž–</button>
              <button data-smark='{"action":"addItem","hotkey":"+"}' title='Insert here'>βž•</button>
            </summary>
            <div class="ep-attendee-details">
              <input data-smark type="email" name="email" placeholder="Email">
              <input data-smark type="tel" name="phone" placeholder="Phone">
            </div>
          </details>
        </li>
      </ul>
    </div>
    <p class="ep-hint">πŸ’‘ Hold <kbd>Ctrl</kbd> to reveal shortcuts</p>
  </div>
</div>
#myForm .ep {
    display: flex;
    flex-direction: column;
    gap: 0.35em;
    max-width: 460px;
    font-size: 0.95em;
}
#myForm .ep p {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin: 0;
}
#myForm .ep label {
    font-weight: 500;
    white-space: nowrap;
}
#myForm .ep label:not(.bullet) {
    min-width: 4.5em;
}
#myForm .ep input {
    padding: 0.3em 0.5em;
    border: 1px solid #ccc;
    border-radius: 4px;
}
#myForm .ep input[type="text"],
#myForm .ep input[type="email"] { flex: 1; }
#myForm .ep fieldset {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0.4em 0.8em 0.6em;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3em;
}
#myForm .ep fieldset legend { font-weight: bold; padding: 0 0.3em; }
#myForm .ep-list ul {
    list-style: none;
    padding: 0;
    margin: 0.2em 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.25em;
}
#myForm .ep-list ul li { display: flex; align-items: flex-start; gap: 0.3em; }
#myForm .ep-list ul li details {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: border-color 0.15s;
}
#myForm .ep-list ul li details[open] {
    border-color: #ccc;
    padding-bottom: 4px;
}
#myForm .ep-list ul li summary {
    display: flex;
    align-items: center;
    gap: 0.4em;
    cursor: default;
    user-select: none;
    padding: 0.1em 0.2em;
    list-style: none;
}
#myForm .ep-attendee-details {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em;
    padding: 0.35em 0.4em 0.1em 1.5em;
}
#myForm .ep-attendee-details input { flex: 1; min-width: 120px; }
#myForm .ep-hint {
    font-size: 0.82em;
    color: #888;
    margin: 0.15em 0 0;
}
#myForm .ep-hint kbd {
    background: #f4f4f4;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 1px 4px;
}
/* Hotkey hints revealed on Ctrl press */
#myForm [data-hotkey]{position:relative}
#myForm [data-hotkey]::after{
    content:"Ctrl+" attr(data-hotkey);
    position:absolute; top:0.75em; left:0;
    font-size:0.7em;
    background:#333; color:#fff;
    padding:1px 4px; border-radius:3px;
    white-space:nowrap;
}
/* Attendee list item entry/exit animations */
#myForm .ep-list ul li.animated_item {
    transform: translateX(-100%);
    opacity: 0;
    transition: transform 200ms ease, opacity 200ms ease;
}
#myForm .ep-list ul li.animated_item.ongoing {
    transform: translateX(0);
    opacity: 1;
}
const myForm = new SmarkForm(document.getElementById("myForm"), {
    "value": {
    "title": "Sprint Review",
    "date": "2025-03-15",
    "time": "10:00:00",
    "organizer": {
        "name": "Alice Johnson",
        "email": "alice@example.com"
    },
    "attendees": [
        {"name": "Bob Smith",    "email": "bob@example.com",   "phone": "+1 555 200 0001"},
        {"name": "Carol White",  "email": "carol@example.com", "phone": "+1 555 200 0002"},
        {"name": "Dave Brown",   "email": "dave@example.com",  "phone": "+1 555 200 0003"}
    ]
}
});const delay = ms=>new Promise(resolve=>setTimeout(resolve, ms));
myForm.onAll("afterRender", async function(ev) {
    if (ev.context.parent?.options.type !== "list") return;
    const item = ev.context.targetNode;
    item.classList.add("animated_item");
    await delay(1);
    item.classList.add("ongoing");
});
myForm.onAll("beforeUnrender", async function(ev) {
    if (ev.context.parent?.options.type !== "list") return;
    const item = ev.context.targetNode;
    item.classList.remove("ongoing");
    await delay(150);
});

What you get

The core model

Developer experience

Additional capabilities

Start where you are

See it

Use it now

Go deeper

Decide whether it fits

Current Status

SmarkForm is stable and in active use, but still pre-1.0: implemented behavior is covered by tests, while the public API may evolve before 1.0.0. Not every initially planned feature is implemented; see the Roadmap for what is planned and what is not.

Last Updated: Sun Nov 15 2026.

Community and Support

If you don’t find a solution in the documentation, feel free to open a discussion on our GitHub repository.

For further support, you can contact me through our Contact Page or reach out via email at smarkform@bitifet.net.

If you want to stay updated with the latest news, releases, and announcements, or join the community chat, you can follow us on Telegram:

πŸš€ Stay tuned

Scan to follow SmarkForm news and announcements on Telegram
News and announcements
Scan to join the SmarkForm Telegram community chat
Community chat

Contributing

We welcome feedback, suggestions, and improvements as we continue to enhance and expand SmarkForm.

πŸ‘‰ See the Contributing section for more details.

License

πŸ”— MIT