Skip to content
ToolPlankDEV
Image & SVG Tools
100% In-Browser Execution

Updated:

HTML to SVG Converter Online

Convert HTML to SVG in your browser. Paste your HTML and CSS and this tool wraps it in an SVG foreignObject with a measured height, valid XML and scripts removed, ready to copy or download as a .svg file.

Options:

HTML

Input
0 chars · 0 lines

SVG

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use HTML to SVG

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your HTML and CSS

    Paste a snippet into the left panel. Inline styles and <style> blocks are kept. The Sample button loads a small styled card so you can see how the result looks.

  2. 02

    Pick the canvas width

    The SVG is 800 px wide by default. Switch on Wide canvas to use 1200 px. The tool lays your HTML out at that width and measures the height for you.

  3. 03

    Copy or download the SVG

    The SVG appears on the right as you type. Use Copy to paste it into your project or Download to save a .svg file. Add the XML declaration if the tool that reads the file asks for it.

  4. 04

    Open it in a browser to check

    Open the saved .svg file in Chrome, Edge, Firefox or Safari. The HTML is drawn inside the SVG using foreignObject. To make a PNG, JPG or WebP from the result, use the SVG to PNG converter.

How HTML to SVG Conversion Works

HTML describes a page with elements that the browser lays out. SVG describes shapes and has no layout engine of its own. The standard way to put HTML inside an SVG is the foreignObject element. This html to svg converter wraps your markup in one, so the browser still lays out the text, boxes and styles.

xml
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="120" viewBox="0 0 800 120">
  <foreignObject x="0" y="0" width="800" height="120">
    <div xmlns="http://www.w3.org/1999/xhtml">Hello</div>
  </foreignObject>
</svg>

Three details make this work reliably. The wrapper must declare the XHTML namespace. The HTML must be well-formed XML, with every tag closed and entities written the XML way. And the SVG needs a width and height that fit the content. The tool takes care of all three: it re-writes your HTML as valid XML, adds the namespace and measures the real height by laying the content out at your chosen width.

What Is Kept, What Is Removed

  • Kept: text, headings, lists, tables, images, inline styles, class names and <style> blocks.
  • Removed for safety: script, iframe, object, embed, link, meta, base and form elements, all on-event attributes such as onclick, and javascript: links. An SVG opened directly in a browser can run script, so the tool never writes it.
  • External CSS files and web fonts are not fetched, so put the CSS in a <style> block and use fonts that are installed on the viewer's device.

When This Is Useful

  • Social cards and badges: design a card in HTML and CSS, wrap it as an SVG and serve it as an image from your own site.
  • README and documentation graphics: SVG files render inside many docs pages and keep their styling.
  • Export to an image: wrap the HTML as an SVG, then turn it into a PNG with SVG to PNG inside the same browser.
  • Learning: see exactly how the XHTML namespace and foreignObject fit together.

If the SVG has to be embedded in CSS or a JSON file, URL Encode and Base64 Encode turn it into a safe data URI string.

Tips for a Clean Result

  • Close all tags and quote all attributes. Fragments such as <br> are written as <br /> automatically.
  • Give the outer element an explicit font-family and font-size. The SVG does not inherit your website's styles.
  • Use pixel units for widths. Percentages are relative to the canvas width you chose.
  • Embed images as data URIs. Images from other sites may be blocked when the SVG is used as an image.

Frequently Asked Questions

Technical Q&A for HTML to SVG

Common questions about edge cases, character encoding, and privacy guarantees.

No. The HTML is wrapped in an SVG foreignObject, so a browser still draws it as HTML. This keeps text selectable and styling exact, but design apps that expect plain paths may not display it.

No. The conversion runs in your browser tab. Your markup is never sent to ToolPlank.

Scripts, forms, iframes and inline event handlers are removed on purpose. An SVG file that contains script can run code when it is opened, so the tool outputs static content only.

SVG needs a size. The tool lays out your HTML at the chosen width, measures its height and writes both into the SVG. If you change the content, run it again to get a new height.

Yes. Use the SVG to PNG converter. Some browsers draw foreignObject text slightly differently when an SVG is converted to a bitmap, so check the result.