> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Svg

> Render inline SVG with automatic sanitization.

`Svg` renders inline SVG markup directly in the page. Content is automatically sanitized to strip scripts and event handlers, making it safe for LLM-generated diagrams, charts, and illustrations.

## Basic Usage

> [card]
>
> ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
> from prefab_ui.components import Svg
>
> Svg(
>     """\
> <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
>   <rect width="200" height="100" rx="10" fill="#4cc9f0"/>
>   <text x="100" y="58" text-anchor="middle"
>         font-size="20" fill="white">Hello SVG</text>
> </svg>""",
>     width="200px",
> )
> ```
>
> ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
> {
>   "view": {
>     "type": "Svg",
>     "content": "<svg viewBox=\"0 0 200 100\" xmlns=\"http://www.w3.org/2000/svg\">\n  <rect width=\"200\" height=\"100\" rx=\"10\" fill=\"#4cc9f0\"/>\n  <text x=\"100\" y=\"58\" text-anchor=\"middle\"\n        font-size=\"20\" fill=\"white\">Hello SVG</text>\n</svg>",
>     "width": "200px"
>   }
> }
> ```

The first positional argument is `content`. Unlike `Embed`, SVG renders inline in the DOM — it participates in the page layout and can be styled with CSS classes.

## Sizing

By default, the SVG renders at its intrinsic size (from `viewBox`). Override with `width` and `height`:

```python Fixed size theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from prefab_ui.components import Svg

Svg(content=diagram_svg, width="400px", height="300px")
```

## Security

All SVG content is sanitized with DOMPurify before rendering. This strips `<script>` tags, event handlers (`onload`, `onclick`, etc.), and other potentially dangerous elements. Safe SVG features — paths, shapes, gradients, filters, text — pass through unchanged.

## API Reference

> [card] Svg Parameters
>
> **content** `str` *required*
>
> SVG markup string.
>
> **width** `str | None` (default: None)
>
> CSS width value with units.
>
> **height** `str | None` (default: None)
>
> CSS height value with units.
>
> **css\_class** `str | None` (default: None)
>
> Additional Tailwind CSS classes.

## Protocol Reference

```json Svg theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "Svg",
  "id?": "string",
  "onMount?": "any",
  "content": "string (required)",
  "width?": "string",
  "height?": "string",
  "cssClass?": "string"
}
```

For the complete protocol schema, see [Svg](https://prefab.prefect.io/docs/protocol/svg.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.