Skip to content
UniKit

Code to SVG image

Render code as a copyable, savable SVG code image: monospace font, line numbers, Dracula / GitHub Light themes and adjustable font size, line height, padding, corner radius and title. The code text is really written into SVG <text> nodes (< and & are XML-escaped), and width is estimated per character (CJK counts as one unit). Output is vector SVG; screenshot it or convert it if you need a PNG.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Input

Result

The result can be copied directly.

Paste code to render an SVG code image

Characters: 0 · Lines: 0 · Width (px): 0 · Height (px): 0

What this tool does

  • Create a line-numbered code image for docs, issues or chat — the page renders the SVG preview right away and hands you the source too.
  • Paste code into slides or blog posts and stay crisp at any zoom; when you need a bitmap, “Export PNG” gives you a PNG at the same size as the preview.
  • One-click export: “Export SVG” downloads the source file and “Export PNG” rasterises the same SVG locally in your browser — no network, no code upload.
  • Compare readability of the dark and light themes.

Example

Input

function hello(name) {
  return `Hello, ${name}!`;
}

Output

<svg xmlns="http://www.w3.org/2000/svg" width="192" height="99" viewBox="0 0 192 99" role="img" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace">
  <rect x="0" y="0" width="192" height="99" rx="8" fill="#282a36" stroke="#44475a" />
  <text x="16" y="30" fill="#6272a4" font-size="14">1</text>
  <text x="35.6" y="30" fill="#f8f8f2" font-size="14" xml:space="preserve">function hello(name) {</text>
  <text x="16" y="51" fill="#6272a4" font-size="14">2</text>
  <text x="35.6" y="51" fill="#f8f8f2" font-size="14" xml:space="preserve">  return `Hello, ${name}!`;</text>
  <text x="16" y="72" fill="#6272a4" font-size="14">3</text>
  <text x="35.6" y="72" fill="#f8f8f2" font-size="14" xml:space="preserve">}</text>
</svg>

The output is SVG source you can save as .svg or embed in a page; the preview and the export buttons on this page both work from that same source, and the PNG is rasterised locally by your browser.

Frequently asked questions

Does the SVG really contain my code?

Yes. Every code line is a separate <text> node with its own line-number node; <, > and & are escaped to entities, so HTML tags or comparison operators cannot break the SVG structure.

Why is the width estimated?

Browsers lay out SVG text with real fonts, so the logic layer estimates for a monospace font: ASCII counts 0.6 of a character width and CJK counts 1, plus padding. Adjust the font size or padding if it looks tight.

Can it export PNG?

Yes, right on the page: “Export PNG” next to the preview draws the same SVG onto a canvas and saves a PNG at the preview size, while “Export SVG” downloads the source file. The logic layer still only produces SVG (no Canvas dependency), so Node tests and the browser agree byte for byte.

How are lines counted?

Lines are split on newlines; blank lines still get a number, and a trailing newline does not add an extra line.

Keywords:code to imagecarbon

Related tools