> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# `<svg>`

APISummary
`<svg>` is the cornerstone element for embedding Scalable Vector Graphics (SVG) directly within your markup. It lets you create crisp, resolution-independent graphics, from simple icons to complex data visualizations, that scale flawlessly across every screen size and pixel density.

Lynx SVG is designed for performant static rendering. Instead of creating individual element nodes on the main thread for each SVG tag, it offloads parsing to a background thread and renders the entire graphic as a single native view, reducing both main-thread parsing time and element node count. It covers 17 commonly used SVG tags and over 40 attributes, sufficient for the vast majority of real-world SVG assets.

## Usage

### Basic

Below is a basic usage example of the `<svg>` element:

**This is an example below: svg**

**Bundle:** `dist/base.lynx.bundle`

```tsx
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { root } from "@lynx-js/react";

const logoContent = `<svg width="320" height="320" viewBox="0 0 320 320" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
  <linearGradient id="panelFill" x1="28" y1="28" x2="292" y2="292" gradientUnits="userSpaceOnUse">
    <stop offset="0%" stop-color="#26292D" stop-opacity="0.72"/>
    <stop offset="55%" stop-color="#4B4F56" stop-opacity="0.62"/>
    <stop offset="100%" stop-color="#8B9098" stop-opacity="0.52"/>
  </linearGradient>
</defs>
<rect x="28" y="28" width="264" height="264" rx="40" fill="url(#panelFill)"/>
<rect x="28.5" y="28.5" width="263" height="263" rx="39.5" stroke="#FFFFFF" stroke-opacity="0.08"/>
<g transform="translate(100 100) scale(6)" opacity="0.98">
  <path fill-rule="evenodd" clip-rule="evenodd" d="M5.19683 4.42475L2.58326 6.22507C2.29923 6.42072 2.10258 6.71472 2.0335 7.04698L1.77798 8.27604C1.76443 8.34121 1.73438 8.40204 1.69058 8.45301L0.504615 10.0077C0.344941 10.1935 0.348791 10.6871 0.786137 11.0031C0.953848 11.1493 1.17807 11.477 1.43312 11.8497L1.43312 11.8497C1.97313 12.639 2.65131 13.6302 3.22376 13.5272C4.03382 13.2426 5.02541 13.1516 5.78673 13.5272C7.2667 14.8049 6.90331 15.983 6.38234 17.672C6.17271 18.3516 5.93755 19.114 5.78673 19.9988C6.49755 17.4117 8.09592 14.4069 10.9781 13.3874C10.4588 12.9632 9.39906 12.5691 8.46129 12.4742C8.46129 12.4742 11.3423 10.0077 14.8957 8.87434C12.4151 2.97197 8.32052 0.151295 8.32052 0.151295C8.11187 -0.10677 7.69054 -0.0221092 7.6036 0.295351C7.53376 1.22845 7.41798 1.86295 7.22685 2.46105L5.78673 0.799291C5.6363 0.61794 5.33557 0.722655 5.33707 0.955861C5.5809 2.31136 5.54668 3.07222 5.19683 4.42475ZM6.21052 4.30085L6.21912 4.3003C6.23794 4.29909 6.25646 4.29664 6.27456 4.29302L6.21052 4.30085ZM8.15541 1.25793C9.1423 2.96321 9.58937 3.932 9.74102 5.73998C8.6912 5.14364 8.23382 4.99187 7.46183 4.99565C7.91215 3.62621 8.04976 2.8016 8.15541 1.25793Z" fill="white"/>
  <path d="M14.4988 13.9228C10.479 14.8427 8.19556 16.2278 6.44922 19.9994C9.58406 14.7399 19.0737 15.6805 19.0737 15.6805C18.8964 14.8214 17.0097 13.183 15.7688 12.1782C15.7688 12.1782 16.7699 10.9474 18.983 10.3244C18.983 10.3244 14.728 10.5709 12.2508 11.9084C13.0533 12.3319 14.0812 13.0467 14.4988 13.9228Z" fill="white"/>
</g>
</svg>`;

const App = () => {
  return (
    <view
      style={{
        width: "100%",
        height: "100%",
        justifyContent: "center",
        alignItems: "center",
        backgroundColor: "#0f0f10",
        padding: "32px",
      }}
    >
      <svg content={logoContent} style={{ width: "320px", height: "320px" }} />
    </view>
  );
};

root.render(<App />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.7.0



### Supported SVG Tags

The following SVG tags are fully supported:

| Tag            | Description                                     |
| -------------- | ----------------------------------------------- |
| circle         | Defines a circle.                               |
| clipPath       | Defines a clipping path.                        |
| defs           | Container for definitions that can be reused.   |
| text           | Defines a text element.                         |
| ellipse        | Defines an ellipse.                             |
| g              | Groups elements together.                       |
| image          | Embeds raster images.                           |
| line           | Defines a straight line.                        |
| linearGradient | Defines a linear gradient.                      |
| path           | Defines a path.                                 |
| polygon        | Defines a closed shape with straight sides.     |
| polyline       | Defines a series of connected straight lines.   |
| radialGradient | Defines a radial gradient.                      |
| rect           | Defines a rectangle.                            |
| stop           | Defines a gradient stop.                        |
| svg            | Root SVG element.                               |
| use            | References and reuses shapes defined elsewhere. |

### Supported SVG Attributes

The following attributes can be applied to the above tags:

| Attribute           | Description                                              |
| ------------------- | -------------------------------------------------------- |
| xlink:href          | Reference to a resource (deprecated, prefer href).       |
| style               | Inline CSS styling.                                      |
| points              | List of points for polygon/polyline.                     |
| offset              | Gradient stop offset.                                    |
| font-size           | Text font size.                                          |
| id                  | Unique identifier.                                       |
| xmlns               | XML namespace.                                           |
| clip-path           | Clipping path reference.                                 |
| clip-rule           | Clipping rule for fill vs. stroke.                       |
| clipPathUnits       | Units for clipPath.                                      |
| color               | Foreground color.                                        |
| cx, cy              | Center coordinates for circles/ellipses.                 |
| d                   | Path data.                                               |
| fill                | Fill color/paint.                                        |
| fill-opacity        | Fill transparency.                                       |
| fill-rule           | Fill rule for intersecting paths.                        |
| fx, fy              | Focal point for radial gradients.                        |
| gradientTransform   | Transform matrix for gradients.                          |
| gradientUnits       | Coordinate system for gradients.                         |
| height, width       | Dimensions.                                              |
| href                | Hyperlink reference (modern replacement for xlink:href). |
| opacity             | Overall transparency.                                    |
| preserveAspectRatio | Aspect ratio behavior on scaling.                        |
| r                   | Radius for circles.                                      |
| rx, ry              | Corner radii for rounded rectangles.                     |
| spreadMethod        | How gradient fills beyond defined range.                 |
| stop-color          | Gradient stop color.                                     |
| stop-opacity        | Gradient stop transparency.                              |
| stroke              | Stroke color/paint.                                      |
| stroke-dasharray    | Dash pattern for strokes.                                |
| stroke-dashoffset   | Offset for dash pattern.                                 |
| stroke-linecap      | Shape at the end of open subpaths.                       |
| stroke-linejoin     | Shape at path corners.                                   |
| stroke-miterlimit   | Limit for miter joins.                                   |
| stroke-opacity      | Stroke transparency.                                     |
| stroke-width        | Stroke thickness.                                        |
| transform           | Transformation matrix.                                   |
| viewBox             | Coordinate system and aspect ratio.                      |
| x, y                | Position coordinates.                                    |
| x1, y1, x2, y2      | Line endpoints.                                          |

## Attributes

### `content`

Android
iOS
Desktop
Harmony
```tsx
content?: string;
```

SVG XML content

### `src`

Android
iOS
Desktop
Harmony
```tsx
src?: string;
```

SVG resource URL

## Events

Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.

### `bindload`

Android
iOS
Desktop
Harmony
```tsx
bindload = (e: BaseEvent) => {};
```

SVG Loaded

## Compatibility

**Compatibility Table**

**Query:** `elements.svg`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/svg.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| svg | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes |
| attributes | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Partial |
| attributes.src | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes |
| attributes.content | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes |
| attributes.current-color | Yes (3.7) | Yes (4.0) | Yes (4.1) | No | No | No |
| events.bindload | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes |
| methods.scrollIntoView | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes |
| methods.setFocus | No | No | No | Yes (3.7) | Yes (3.7) | No |

**`svg`**

svg

**`attributes`**

attributes

- **Web — Supported (version unknown):** Partial support; Web Lynx implements only part of this grouped feature.

**`attributes.src`**

<code>src</code>

**`attributes.content`**

<code>content</code>

**`attributes.current-color`**

<code>current-color</code>

**`events.bindload`**

<code>bindload</code>

**`methods.scrollIntoView`**

<code>scrollIntoView</code>

**`methods.setFocus`**

<code>setFocus</code>

