For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/elements/svg.md.

<svg>

Draws SVG from a markup string or a URL. Unlike HTML, you can't write SVG tags in the template: pass the markup as text, and give the element a width and height.

Usage

src/app/dot.ts
import { Component } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-dot',
  imports: [LYNX_ELEMENTS],
  template: `<svg [content]="icon" style="width: 24px; height: 24px;" />`,
})
export class Dot {
  readonly icon = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
    <circle cx="12" cy="12" r="10" fill="#dd0031" />
  </svg>`;
}

Import LYNX_ELEMENTS in your component (see Elements).

Warning

Needs XElement in custom native apps (see Embedding).

Attributes

AttributeTypeDefaultDescription
contentstring—SVG markup to draw. See Writing the markup.
srcstring—URL of an SVG file. Use src or content, not both.
current-colorstring—iOS (Lynx 4.1 and later) and Android. The color currentColor stands for in the SVG. It doesn't override an explicit fill or stroke.

Plus the common attributes, such as id, class and style.

Writing the markup

  • No CSS variables or page styles. The markup can't use them.
  • Draw lines with <path>. <line> doesn't show on iOS and Android.
  • Give the root <svg> xmlns="http://www.w3.org/2000/svg". Without it, the web preview draws nothing.
  • AngularLynx removes stroke-dasharray values iOS can't parse, such as none. They would blank every SVG in the app.

Events

Read the payload from $event.detail. Angular types $event for each event: see Element events.

EventdetailDescription
bindload{ width: number; height: number }The SVG was drawn.

Plus the common events, such as bindtap.

  • <image>: PNG, JPEG, WebP and GIF images
  • Icon: the UI component that draws icons with <svg>
  • Chart: charts drawn with <svg>