Lynx

<svg> XElement

<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:

Supported SVG Tags

The following SVG tags are fully supported:

TagDescription
circleDefines a circle.
clipPathDefines a clipping path.
defsContainer for definitions that can be reused.
textDefines a text element.
ellipseDefines an ellipse.
gGroups elements together.
imageEmbeds raster images.
lineDefines a straight line.
linearGradientDefines a linear gradient.
pathDefines a path.
polygonDefines a closed shape with straight sides.
polylineDefines a series of connected straight lines.
radialGradientDefines a radial gradient.
rectDefines a rectangle.
stopDefines a gradient stop.
svgRoot SVG element.
useReferences and reuses shapes defined elsewhere.

Supported SVG Attributes

The following attributes can be applied to the above tags:

AttributeDescription
xlink:hrefReference to a resource (deprecated, prefer href).
styleInline CSS styling.
pointsList of points for polygon/polyline.
offsetGradient stop offset.
font-sizeText font size.
idUnique identifier.
xmlnsXML namespace.
clip-pathClipping path reference.
clip-ruleClipping rule for fill vs. stroke.
clipPathUnitsUnits for clipPath.
colorForeground color.
cx, cyCenter coordinates for circles/ellipses.
dPath data.
fillFill color/paint.
fill-opacityFill transparency.
fill-ruleFill rule for intersecting paths.
fx, fyFocal point for radial gradients.
gradientTransformTransform matrix for gradients.
gradientUnitsCoordinate system for gradients.
height, widthDimensions.
hrefHyperlink reference (modern replacement for xlink:href).
opacityOverall transparency.
preserveAspectRatioAspect ratio behavior on scaling.
rRadius for circles.
rx, ryCorner radii for rounded rectangles.
spreadMethodHow gradient fills beyond defined range.
stop-colorGradient stop color.
stop-opacityGradient stop transparency.
strokeStroke color/paint.
stroke-dasharrayDash pattern for strokes.
stroke-dashoffsetOffset for dash pattern.
stroke-linecapShape at the end of open subpaths.
stroke-linejoinShape at path corners.
stroke-miterlimitLimit for miter joins.
stroke-opacityStroke transparency.
stroke-widthStroke thickness.
transformTransformation matrix.
viewBoxCoordinate system and aspect ratio.
x, yPosition coordinates.
x1, y1, x2, y2Line endpoints.

Attributes

content

Android
iOS
Clay
Harmony
content?: string;

SVG XML content

src

Android
iOS
Clay
Harmony
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
Clay
Harmony
bindload = (e: BaseEvent) => {};

SVG Loaded

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.