SVT makes text, colors, and images editable through named inputs. This guide shows how to pair those inputs with built-in SVG features so labels stay centered as they grow and replacement images fit their frames.
Text
Replace a line of text
data-svt-text makes a line of text editable.
The <text> element supplies the default destination, “North Pier.” When SVT binds a value to destination, it replaces that element’s text content. SVG keeps the position, font, and color defined on the element.
text-anchor="middle" keeps a name centered as its length changes.
SVT replaces the place name. SVG centers the new text on the x coordinate marked by the two ticks. The rendered width depends on the name and font, so a long name can still extend beyond the label.
A separate <tspan> lets the number change while its unit stays beside it.
Only the first <tspan> carries data-svt-text. SVG positions the second <tspan> after the replacement number, with dx adding a small gap before the unit. An empty text value clears the number and leaves the unit visible.
textLength gives short and long names the same width on the sign.
After SVT replaces the name, SVG fits the text to textLength="512". With lengthAdjust="spacingAndGlyphs", both letter spacing and glyph widths can change to reach that length.
A <textPath> carries an editable name around the top of a seal.
SVT binds the port name inside the leaf <tspan>. SVG lays the letters along the path referenced by href. With startOffset="50%" and text-anchor="middle", the midpoint of the lettering stays at the midpoint of the curve.
data-svt-image makes the artwork in a postcard replaceable.
The <image> element gets its starting artwork from href. SVT embeds the selected artwork in that attribute, and SVG uses the element’s width and height to size the replacement. A relative href such as artwork/postcard.png resolves against the SVG document’s base URL. Moving the SVG changes where a viewer looks for that file. Preserve the directory layout, update the reference, or embed the image as the cookbook downloads do.
preserveAspectRatio lets a frame show the whole image or crop it to fill the space.
Both <image> elements use data-svt-image="artwork", so one image choice updates both frames. With meet, SVG scales the whole image to fit inside the frame. With slice, it fills the frame and crops the excess. Both use xMidYMid to center the result.
Corner alignment chooses which edge survives a crop. none stretches the whole image into the frame.
All three frames share the artwork input. The wide headland loses its right edge with xMinYMin slice and its left edge with xMaxYMax slice. Switching to the tall beacon moves the crop to the bottom or top instead. In the third frame, preserveAspectRatio="none" scales each axis independently, turning the round sun into an oval.
One rounded rectangle shapes the image and supplies its editable border.
A <clipPath> uses the rectangle to trim the image corners. A second <use> draws the same outline over the image with fill="none". SVT binds the border color through data-svt-stroke. The stroke-width sets the thickness, with half the stroke on each side of the edge.
A smaller viewBox enlarges the outlined part of the image while keeping its proportions.
The whole image fits inside a 200 × 200 drawing area using xMidYMid meet. The detail’s viewBox="65 48 100 100" starts 65 units from the left and 48 from the top. Its 100 × 100 area fills a 200 × 200 frame at 2× scale. The first two numbers position the crop. Reducing the last two in the same proportion zooms in further. Zoom and clipping change what is visible. The complete image remains in the SVG. To discard pixels or reduce the embedded payload, crop and re-encode the source before binding it.
A gradient in a <mask> blends the edge of a replaceable image into the page.
The white mask fades from transparent to opaque as stop-opacity increases. SVG reveals progressively more of the image across that transition. SVT updates href on the <image>, so each replacement uses the same fade.
The picker reads the authored rgb(206 99 71) color. The template keeps that spelling until a replacement is bound to pennant, which updates the path’s fill attribute.
A shared input key lets one color control both fill and stroke.
The pin’s data-svt-fill and the route’s data-svt-stroke both name the route input. An assignment to route updates both attributes. Omitting it preserves each path’s original color.
A CSS rule can keep a shape the same color even when its fill attribute changes.
SVT writes the selected color to fill on both circles. The left circle takes its color from that attribute. On the right circle, the .signal rule takes precedence, so SVG continues to render the color from the stylesheet.
Keep highlights and shadows when recoloring a shape
A translucent gradient adds depth to a shape with an editable base color.
SVT updates fill on the lower circle. SVG paints a second circle over it using <radialGradient>. The transparent middle reveals the base color, while the pale and dark stops tint the highlight and shadow.
Separate inputs make the boat name and its background color independently editable.
SVG draws the <rect> before the <text>, placing the name on top of the panel. SVT binds panel to the rectangle’s fill and name to the lettering. Binding either input preserves the drawing order.
A <clipPath> gives each replacement image the same arched outline.
SVT replaces the artwork in the <image> element. SVG scales it to cover the image area, then applies clip-path="url(#arch)" so only the portion inside the arch is visible.
One data-svt-text key gives the ticket and its stub the same editable number.
Both <text> elements declare data-svt-text="ticket". SVT lists one field and writes its value to both elements. SVG draws the number at each element’s own position, size, and color.
<imagex="206"y="30"width="308"height="178"href="…"data-svt-image="print"data-svt-label="View from the lookout"/>
Add help text to a field
<svt:description> adds a short explanation beneath a form field.
The <svt:input> declaration refers to the eta text input by key. Its label supplies the field name, and its <svt:description> provides the 24-hour time hint. SVT binds the entered time as ordinary text.
<metadataxmlns:svt="https://svt-project.github.io/ns/svt"xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:RDF><rdf:Descriptionrdf:about=""><svt:inputsrdf:parseType="Literal"><svt:inputkey="eta"label="Arrival time"><svt:description>Use local harbor time in 24-hour format.</svt:description></svt:input></svt:inputs></rdf:Description></rdf:RDF></metadata><textx="132"y="205"font-family="monospace"font-size="80"fill="#fff0ce"data-svt-text="eta">17:20</text>
Group fields and set their order
<svt:group> puts related fields together, and order sets their sequence in the form.
Each <svt:input> names its group with the group attribute. SVT uses ascending order values to arrange the groups and the fields within each group. Here, “Trip details” comes before “Appearance,” even though SVG draws the colored panel first.
<svt:inputsrdf:parseType="Literal"><svt:groupkey="style"label="Appearance"order="20"/><svt:groupkey="trip"label="Trip details"order="10"><svt:description>These details appear on the printed pass.</svt:description></svt:group><svt:inputkey="panel"label="Panel color"group="style"/><svt:inputkey="port"label="Destination"group="trip"order="20"/><svt:inputkey="holder"label="Passenger name"group="trip"order="10"/></svt:inputs>
Checking a template
These recipes use SVT 1.0.0. The observations below come from Chromium 159.0.8154.6, Firefox 159.0, and WebKit 27.2 on macOS. Print, PDF export, and other font installations need their own visual check.
Leave room for font fallback
In the centered label, the name uses Georgia,serif at 52 units. The label is 620 units wide. Here are the measured text advances, rounded to the nearest SVG unit. To try the fallback in the template editor, replace Georgiawith a missing family name and keep serif.
Width of the same binding with two font choices
Place
Georgia
Fallback serif
Flores
143
130
Northumberland Passenger Terminal
859
764–768
Empty string
0
0
São Tomé 港
292
273–277
The long name overflowed in every run. Clearing the field removed the lettering and left the registration marks in place. A renderer can select another font for an individual glyph, so check names that use the scripts your readers will enter.
Check the crop with a second image
In the corner comparison, all three renderers cropped the 960 × 540 headland horizontally and the 480 × 660 beacon vertically. The headland sun disappeared in the top-left crop and stayed round in the bottom-right crop. Stretching the whole headland made the sun tall and narrow. The same stretch made the beacon sun wide and short.
Check an editor save and export
Download the grouped form template. Save a copy in your SVG editor. If you distribute an optimized export, check that file too.
Paste each saved file into the grouped form’s template editor. Compare the fields, their labels, defaults, help text, and order with the original. The passenger and destination fields belong under “Trip details” and the panel color under “Appearance.”
Bind each field and reset it. If a field is missing, inspect its data-svt-* attribute and the root’s data-svt-version. If a label or group changed, compare thesvt:inputs metadata and its namespace. A visually identical export can lose a hook or convert editable text to paths.
To inspect the input inventory and bind a downloaded template from the command line, see the .NET authoring walkthrough.