DEV Community

Cover image for Embed a visual HTML + Tailwind editor in any page with one script tag
swapnil jadhav
swapnil jadhav

Posted on

Embed a visual HTML + Tailwind editor in any page with one script tag

I've been building a visual editor for HTML + Tailwind, and I published the editor as an npm package so you can put it in your own site or app. You select, drag and style like Figma, and every change is real Tailwind classes in plain HTML. There is no export step and no format of its own.

The smallest version

One file:

<div id="root"></div>
<script type="module">
  import { startEditor } from "https://cdn.jsdelivr.net/npm/windcraft-editor/editor/index.js";
  startEditor(document.getElementById("root"), {
    html: '<h1 class="p-10 text-4xl font-bold">Hello</h1>'
  });
</script>
Enter fullscreen mode Exit fullscreen mode

Edit the heading on the canvas and the HTML follows. Set new HTML from code and the canvas follows.

The editor embedded in a page: the HTML updates as you edit

Three ways to use it

  • startEditor runs the editor as a whole page and saves designs in the browser.
  • mountEditor saves to your own server, through a few functions you write.
  • embedEditor puts it in one box of a page, such as a CMS field or a form. You read the HTML back with getHtml() or onChange.

It works with React, Vue and Next: serve the package folder as static files and import it from an effect. The docs have the snippets.

What you get

  • Zero dependencies, no build step, MIT licensed
  • 89 files, about 820 kB to download (2.7 MB unpacked)
  • Plain Tailwind HTML in and out, so it fits whatever you already render

Honest limits

It loads Tailwind's play CDN inside the editor, and I have only tested it in Chrome so far. Safari and Firefox are next.

Try it

If you embed it somewhere, I would like to hear what got in the way.

Top comments (0)