SVT

Authoring Guide

Overview

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.

Ferry departure board with a destination beneath the words Next sailing.

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
  x="48"
  y="185"
  font-size="62"
  font-family="Georgia,serif"
  fill="#fff5d8"
  data-svt-text="destination">North Pier</text>

Keep changing text centered

text-anchor="middle" keeps a name centered as its length changes.

Cream archive label with a place name centered between two registration marks.

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.

<text
  x="360"
  y="163"
  text-anchor="middle"
  font-family="Georgia,serif"
  font-size="52"
  fill="#193f3d"
  data-svt-text="place">Flores</text>

Keep a unit beside an editable number

A separate <tspan> lets the number change while its unit stays beside it.

Tide gauge with a reading followed by a smaller m for meters.

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.

<text x="45" y="185" fill="#fff6d9" font-size="86"><tspan data-svt-text="depth">2.4</tspan><tspan dx="9" font-size="30">m</tspan></text>

Fit text to a fixed width

textLength gives short and long names the same width on the sign.

Harbor name stretched between two vertical guides.

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.

<text
  x="104"
  y="172"
  textLength="512"
  lengthAdjust="spacingAndGlyphs"
  font-family="Georgia,serif"
  font-size="75"
  fill="#653d31"
  data-svt-text="harbor">West Bay</text>

Set editable text along a curve

A <textPath> carries an editable name around the top of a seal.

A port name arcs over a sailboat 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.

<defs>
    <path id="lettering" d="M90 188 Q360 -60 630 188"/>
  </defs>
<text font-family="Georgia,serif" font-size="36" text-anchor="middle"><textPath href="#lettering" startOffset="50%"><tspan data-svt-text="port" data-svt-label="Port name">Port Meridian</tspan></textPath></text>

Images

Replace an image

data-svt-image makes the artwork in a postcard replaceable.

A single coastal illustration mounted on a postcard.

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.

<image
  x="210"
  y="28"
  width="300"
  height="184"
  href="…"
  data-svt-image="illustration"/>

Fit or crop an image to a frame

preserveAspectRatio lets a frame show the whole image or crop it to fill the space.

The same coastal illustration in two frames labeled Contain and Crop.

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.

<image
  x="96"
  y="32"
  width="200"
  height="174"
  preserveAspectRatio="xMidYMid meet"
  data-svt-image="artwork"
  data-svt-label="Illustration"
  href="…"/>
<image
  x="424"
  y="32"
  width="200"
  height="174"
  preserveAspectRatio="xMidYMid slice"
  data-svt-image="artwork"
  data-svt-label="Illustration"
  href="…"/>

Keep one corner visible when cropping an image

Corner alignment chooses which edge survives a crop. none stretches the whole image into the frame.

Three square frames show the top-left crop, bottom-right crop, and stretched whole illustration.

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.

<image
  x="44"
  y="32"
  width="180"
  height="180"
  preserveAspectRatio="xMinYMin slice"
  data-svt-image="artwork"
  data-svt-label="Illustration"
  href="…"/>
<image
  x="270"
  y="32"
  width="180"
  height="180"
  preserveAspectRatio="xMaxYMax slice"
  data-svt-image="artwork"
  data-svt-label="Illustration"
  href="…"/>
<image
  x="496"
  y="32"
  width="180"
  height="180"
  preserveAspectRatio="none"
  data-svt-image="artwork"
  data-svt-label="Illustration"
  href="…"/>

Add a border to a replaceable image

One rounded rectangle shapes the image and supplies its editable border.

A coastal print with a colored border that follows its rounded corners.

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.

<defs>
    <rect id="frame" x="158" y="30" width="404" height="220" rx="16"/>
    <clipPath id="window"><use href="#frame"/></clipPath>
  </defs>
<image
  x="158"
  y="30"
  width="404"
  height="220"
  href="…"
  preserveAspectRatio="xMidYMid slice"
  clip-path="url(#window)"
  data-svt-image="print"
  data-svt-label="Coastal print"/>
<use
  href="#frame"
  fill="none"
  stroke="#286258"
  stroke-width="10"
  data-svt-stroke="border"
  data-svt-label="Border color"/>

Zoom in on part of an image

A smaller viewBox enlarges the outlined part of the image while keeping its proportions.

A dashed square marks a detail on the full illustration. The neighboring frame shows that region at twice the size.

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.

<defs>
    <image
    id="plate"
    width="200"
    height="200"
    preserveAspectRatio="xMidYMid meet"
    href="…"
    data-svt-image="artwork"
    data-svt-label="Coastal view"/>
  </defs>
<svg x="92" y="20" width="200" height="200" viewBox="0 0 200 200">
    <rect width="200" height="200" fill="#fff8e8"/>
    <use href="#plate"/>
    <rect
    x="65"
    y="48"
    width="100"
    height="100"
    fill="none"
    stroke="#284a46"
    stroke-width="3"/>
    <rect
    x="65"
    y="48"
    width="100"
    height="100"
    fill="none"
    stroke="white"
    stroke-dasharray="5 4"/>
  </svg>
<svg
  x="428"
  y="20"
  width="200"
  height="200"
  viewBox="65 48 100 100"
  preserveAspectRatio="xMidYMid meet"
  overflow="hidden">
    <use href="#plate"/>
  </svg>

Fade an image into its background

A gradient in a <mask> blends the edge of a replaceable image into the page.

A coastal view gradually emerges from the cream background beside a field-note title.

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.

<defs>
    <linearGradient id="fade">
      <stop offset="28%" stop-color="white" stop-opacity="0"/>
      <stop offset="76%" stop-color="white" stop-opacity="1"/>
    </linearGradient>
    <mask id="reveal"><rect width="720" height="280" fill="url(#fade)"/></mask>
  </defs>
<image
  width="720"
  height="280"
  href="…"
  preserveAspectRatio="xMidYMid slice"
  mask="url(#reveal)"
  data-svt-image="view"
  data-svt-label="Coastal view"/>

Color

Change a shape’s fill color

data-svt-fill makes the pennant’s color editable.

A triangular harbor pennant flying from a dark mast.

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.

<path d="M262 64L500 106L262 158Z" fill="rgb(206 99 71)" data-svt-fill="pennant"/>

Share one color across fills and strokes

A shared input key lets one color control both fill and stroke.

Map with a dashed route from West Pier to a pin at Beacon Hill.

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.

<path
  d="M154 184Q235 126 315 148T490 95"
  fill="none"
  stroke="#457f78"
  stroke-width="5"
  stroke-dasharray="8 6"
  data-svt-stroke="route"/>
<path
  d="M490 103q-30 -31 -30 -48a30 30 0 1 1 60 0q0 17 -30 48Z"
  fill="#b85839"
  data-svt-fill="route"/>

Find out why a fill color won’t change

A CSS rule can keep a shape the same color even when its fill attribute changes.

Two signal discs, one painted by an attribute and one by a class rule.

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.

<style>.signal { fill: #bb5637; }</style>
<g stroke="#343f38" stroke-width="3">
    <circle cx="220" cy="115" r="62" fill="#bb5637" data-svt-fill="paint"/>
    <circle cx="500" cy="115" r="62" class="signal" fill="#bb5637" data-svt-fill="paint"/>
  </g>

Keep highlights and shadows when recoloring a shape

A translucent gradient adds depth to a shape with an editable base color.

A spherical fishing float has a pale highlight near its top and a shaded lower rim.

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.

<defs>
    <radialGradient id="glaze" cx="35%" cy="28%" r="76%">
      <stop offset="0" stop-color="white" stop-opacity=".65"/>
      <stop offset=".46" stop-color="white" stop-opacity="0"/>
      <stop offset="1" stop-color="#102d35" stop-opacity=".72"/>
    </radialGradient>
  </defs>
<circle
  cx="325"
  cy="144"
  r="92"
  fill="#c46a43"
  data-svt-fill="enamel"
  data-svt-label="Float color"/>
<circle cx="325" cy="144" r="92" fill="url(#glaze)"/>

Composition

Layer editable text over a background

Separate inputs make the boat name and its background color independently editable.

A colored panel with a boat name printed across it.

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.

<rect
  x="50"
  y="52"
  width="620"
  height="176"
  rx="12"
  fill="#305957"
  data-svt-fill="panel"/>
<text
  x="360"
  y="163"
  text-anchor="middle"
  font-family="Georgia,serif"
  font-size="54"
  fill="#fff6db"
  data-svt-text="name">Sea Wren</text>

Clip a replaceable image to a shape

A <clipPath> gives each replacement image the same arched outline.

Gallery card with a title on the left and an arched coastal print on the right.

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.

<defs><clipPath id="arch"><path d="M400 250V138a112 112 0 0 1 224 0v112Z"/></clipPath></defs>
<rect x="37" y="36" width="55" height="7" fill="#bc6749" data-svt-fill="accent"/>
<text
  x="37"
  y="150"
  font-family="Georgia,serif"
  font-size="38"
  fill="#234d47"
  data-svt-text="title">Inshore waters</text>
<path d="M38 186H340" stroke="#bc6749" stroke-width="2" data-svt-stroke="accent"/>
<image
  x="400"
  y="26"
  width="224"
  height="224"
  preserveAspectRatio="xMidYMid slice"
  clip-path="url(#arch)"
  data-svt-image="print"
  data-svt-label="Illustration"
  href="…"/>

Show one editable value in two places

One data-svt-text key gives the ticket and its stub the same editable number.

A passenger ticket and its detachable claim stub carry the same serial number in two sizes.

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.

<text
  x="68"
  y="172"
  font-size="46"
  fill="#284d46"
  data-svt-text="ticket"
  data-svt-label="Ticket number">FM-0824</text>
<text
  x="530"
  y="164"
  font-size="21"
  fill="#78452f"
  data-svt-text="ticket"
  data-svt-label="Ticket number">FM-0824</text>

Metadata

Give a form field a readable label

data-svt-label gives an editable field a readable name.

A coastal print in a cream mount with the caption From the lookout.

The form displays “View from the lookout” from the inline label. SVT still identifies the image input by print, the key declared in data-svt-image.

<image
  x="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.

A harbor arrival board displaying a time in large numerals.

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.

<metadata
  xmlns:svt="https://svt-project.github.io/ns/svt"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:RDF>
      <rdf:Description rdf:about="">
        <svt:inputs rdf:parseType="Literal">
          <svt:input key="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>
<text
  x="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.

A harbor pass with a passenger name and destination on a colored panel.

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:inputs rdf:parseType="Literal">
          <svt:group key="style" label="Appearance" order="20"/>
          <svt:group key="trip" label="Trip details" order="10">
            <svt:description>These details appear on the printed pass.</svt:description>
          </svt:group>
          <svt:input key="panel" label="Panel color" group="style"/>
          <svt:input key="port" label="Destination" group="trip" order="20"/>
          <svt:input key="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
PlaceGeorgiaFallback serif
Flores143130
Northumberland Passenger Terminal859764–768
Empty string00
São Tomé 港292273–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

  1. Download the grouped form template. Save a copy in your SVG editor. If you distribute an optimized export, check that file too.
  2. 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.”
  3. 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.