# SVG Support GTML supports inline SVG (Scalable Vector Graphics) for rendering vector icons and graphics. SVGs are rendered using Godot's drawing API through a custom `SvgDrawControl`. ## Basic Usage ```html ``` ## SVG Attributes | Attribute | Description | Example | |-----------|-------------|---------| | `viewBox` | Defines the coordinate system | `"0 0 24 24"` | | `width` | Display width in pixels | `"32"` | | `height` | Display height in pixels | `"32"` | | `stroke` | Default stroke color | `"#ffffff"` | | `fill` | Default fill color | `"#00d4ff"` | | `stroke-width` | Default stroke width | `"2"` | ## Supported Elements ### Circle ```html ``` **Attributes:** `cx`, `cy`, `r`, `fill`, `stroke`, `stroke-width` ### Ellipse ```html ``` **Attributes:** `cx`, `cy`, `rx`, `ry`, `fill`, `stroke`, `stroke-width` ### Rectangle ```html ``` **Attributes:** `x`, `y`, `width`, `height`, `rx`, `ry` (corner radius), `fill`, `stroke`, `stroke-width` ### Line ```html ``` **Attributes:** `x1`, `y1`, `x2`, `y2`, `stroke`, `stroke-width` ### Polygon Closed shape defined by points. ```html ``` **Attributes:** `points`, `fill`, `stroke`, `stroke-width` ### Polyline Open shape defined by points (no automatic closing). ```html ``` **Attributes:** `points`, `fill`, `stroke`, `stroke-width` ### Path Complex shapes using SVG path commands. ```html ``` **Attributes:** `d` (path data), `fill`, `stroke`, `stroke-width` ### Group Groups elements with shared styling. ```html ``` Child elements inherit `fill`, `stroke`, and `stroke-width` from the group. ## Path Commands The `d` attribute in `` supports these commands: | Command | Description | Parameters | |---------|-------------|------------| | `M` / `m` | Move to | `x y` | | `L` / `l` | Line to | `x y` | | `H` / `h` | Horizontal line | `x` | | `V` / `v` | Vertical line | `y` | | `Z` / `z` | Close path | (none) | | `C` / `c` | Cubic bezier* | `x1 y1 x2 y2 x y` | | `S` / `s` | Smooth cubic* | `x2 y2 x y` | | `Q` / `q` | Quadratic bezier* | `x1 y1 x y` | | `T` / `t` | Smooth quadratic* | `x y` | Uppercase = absolute coordinates, lowercase = relative coordinates. > **Note:** Bezier curves (C, S, Q, T) are simplified to straight lines between start and end points. Arc commands (A) are not supported. ### Path Examples ```html ``` ## Color Values SVG elements support these color formats: ```html ``` **Named colors:** white, black, red, green, blue, yellow, cyan, magenta, gray, orange, purple, pink, transparent ## CSS Color Inheritance SVGs inherit the `color` CSS property for stroke: ```html ``` ```css .icon-button { color: #ffaa00; /* SVG will inherit this for stroke */ } .icon-button:hover { color: #ffcc00; /* SVG stroke changes on hover */ } ``` ## Sizing ### Fixed Size ```html ``` ### CSS Sizing ```html ``` ```css .icon-large { width: 64px; height: 64px; } ``` ### ViewBox Scaling The `viewBox` defines the coordinate system. Content scales to fit the display size while maintaining aspect ratio: ```html ... ... ... ``` ## Complete Examples ### Settings Icon ```html ``` ### Play Button ```html ``` ### Checkmark ```html ``` ### Menu Icon (Hamburger) ```html ``` ### Close Icon (X) ```html ``` ## Using SVGs in Buttons ```html ``` ```css .icon-btn { width: 40px; height: 40px; padding: 8px; background-color: transparent; border: 1px solid #3a3a5e; border-radius: 4px; color: #ffffff; } .icon-btn:hover { background-color: #3a3a5e; color: #00d4ff; } .play-btn { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 12px 20px; color: #000000; background-color: #00d4ff; } .play-btn svg { width: 16px; height: 16px; } ``` ## Limitations - **Bezier curves** (C, S, Q, T) render as straight lines to endpoints - **Arc command** (A) is not supported - **Transforms** (`transform` attribute) not supported - **Masks and filters** not supported - **Text elements** (``) not supported - **Gradients** (``, ``) not supported - **Use/defs** (``, ``) not supported ## See Also - [HTML Elements](html-elements.md) - SVG in context - [CSS Properties](css-properties.md) - Styling with CSS - [Limitations](limitations.md) - Full limitations list