CommunityImagegithub.com

SVG Foundry

Draw, fix, animate, and slim SVG for icons, logos, illustrations, charts, spinners, and badges. A checker catches broken gradients, duplicate ids, and graphics that will not scale.

What is SVG Foundry?

SVG Foundry is a hand-built vector practice with a deep reference and a checker that runs before delivery. It covers paths, viewBox, gradients, filters, masks, text, CSS and SMIL animation, and accessibility. Use it whenever the graphic has to stay sharp at any size, including when nobody said the word SVG. It also repairs exports from Illustrator or Inkscape that look fine until they are embedded.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/saltless-bruh/lazysvg/tree/HEAD/skills/svg-foundry

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

What does SVG Foundry do?

SVG is small enough to write by hand and subtle enough to get quietly wrong. A graphic can open fine in a browser and still be broken: a gradient referenced before it was defined paints nothing, two elements sharing an id make url(#x) pick the wrong one, a missing viewBox pins the artwork to one size the moment it is embedded. None of these raise an error.

So this skill is built around two things: a reference library deep enough to answer the hard questions, and a checker that catches the quiet failures before the user sees them.

request ──▶ infer intent ──▶ build ──▶ check_svg.py ──▶ deliver
                 │                          │
                 ▼                          ▼
          <library>/INDEX.md         refs resolve? ids unique?
          (120 chapters, load         scalable? accessible?
           only what you need)

The reference library is the point — use it

The library holds 120 chapters from five SVG books, about 400,000 words. It is there so you can answer precisely instead of approximating.

It is not bundled with the skill. It downloads once, the first time you need it (under 1 MB, a few seconds), and is instant after that. Before reading your first chapter, run:

python3 "${CLAUDE_SKILL_DIR}/scripts/setup_library.py" --plugin-data "${CLAUDE_PLUGIN_DATA}"

The last line it prints is LIBRARY=<path>. Every chapter named below is a file in that directory, and INDEX.md there maps all of them. If the placeholders in that command came through unfilled (empty, or still showing ${…}), substitute the base directory this skill was loaded from for ${CLAUDE_SKILL_DIR} and drop the --plugin-data argument. If the download fails, for example offline, tell the user and carry on from this file. A missing library should not block the task. Load a chapter when the task turns on a detail you would otherwise guess at — how gradientUnits changes coordinate meaning, how preserveAspectRatio actually crops, why multiline text needs <tspan> rather than \n.

These are the chapters worth knowing by name:

NeedRead
viewBox, units, coordinate systemsessentials-ch04.md, web-ch21.md
path commands, curves, arcsessentials-ch08.md, web-ch16.md
transforms, nesting, rotation centersessentials-ch07.md, web-ch27.md
gradients: linear, radial, units, spreadcolors-ch09.md–colors-ch12.md
patterns and texturescolors-ch13.md, colors-ch14.md
filters: blur, shadow, color, turbulenceessentials-ch11.md, web-ch37.md
clipping and maskingessentials-ch10.md, web-ch35.md
strokes, dashes, line joinsweb-ch31.md
markers and arrowheadsweb-ch33.md
text basics and stylingtext-ch04.md, text-ch05.md
multiline text (no \n in SVG)text-ch07.md
text alignment and anchoringtext-ch09.md, text-ch11.md
RTL / CJK / international texttext-ch10.md
fitting text to a widthtext-ch14.md
text on a pathtext-ch12.md
CSS animation on SVGanimation-ch04.md, web-ch44.md
SMIL (<animate>, path morphing)essentials-ch12.md
animating color, gradients, stopscolors-ch17.md
UI motion: loaders, hover, micro-interactionsanimation-ch07.md
chart and data-driven motionanimation-ch08.md
interactivity, events, scriptingessentials-ch13.md, web-ch42.md
generating SVG programmaticallyessentials-ch15.md
embedding: inline vs img vs objectweb-ch08.md, modern-ch04.md
accessibility, ARIA, title/descweb-ch40.md
performance and best practicesweb-ch47.md, web-ch46.md
color keyword / attribute lookupcolors-ch18.md, colors-ch19.md

INDEX.md in the library lists all 120 chapters with real titles and word counts. Go there when the table above does not cover the need. Word count is the signal worth trusting: entries under ~200 words are part dividers with no body, and book indexes are marked — loading those wastes a read for nothing.

Step 1 — Read the request before asking about it

Most requests already say what they need. "A gear icon for a settings button" fixes the subject, the size class, and the fact that it wants a flat monochrome icon rather than an illustration. Build that, and show it.

Ask a question only when the answer would change the markup materially and you genuinely cannot tell — most often the delivery format, when the surrounding context gives no hint:

  • a bare .svg file, embeddable anywhere
  • an HTML page with inline SVG and a <style> block (needed for CSS animation)
  • a React component with props for size and color
  • a Vue SFC

Even then, prefer inferring from context over interrupting: a request mentioning a React app wants a component; one mentioning a README wants a file. When the context is truly silent and the choice matters, a single AskUserQuestion is right — but asking for confirmation on an obvious request costs the user a round-trip and buys nothing.

Offering two or three variants is often better than asking. Icons and logos are taste, and showing beats describing.

Step 2 — Build it

You already know <rect>, <circle>, and M/L/C/Z. What follows is the part that is genuinely easy to get wrong.

Always set viewBox; choose width/height by how the SVG is embedded. viewBox="0 0 24 24" defines the coordinate space and is what lets the graphic scale. Whether to add fixed dimensions depends on the consumer:

  • Inline in HTML or a component (icons, UI graphics sized by CSS): omit them, or the hardcoded size fights the stylesheet.
  • Used through <img>, a README, or as a standalone file (badges, logos, illustrations): include them, at the same aspect ratio as the viewBox. They set the intrinsic size; without them an <img> falls back to a browser default (often 300×150 or the full container width), and CSS can still override them.

A width/height ratio that disagrees with the viewBox letterboxes the art, so keep the two consistent. Remember the y-axis points down.

Define every paint before you reference it. A fill="url(#grad)" needs its <linearGradient id="grad"> present, inside <defs>. This is the most common way generated SVG breaks, and it fails silently — the shape renders unpainted.

<defs>
  <linearGradient id="skyFade" x1="0" y1="0" x2="0" y2="1">
    <stop offset="0" stop-color="#0b1026"/>
    <stop offset="1" stop-color="#2b3f6b"/>
  </linearGradient>
</defs>
<rect width="100%" height="100%" fill="url(#skyFade)"/>

gradientUnits decides what the numbers mean. Default objectBoundingBox treats coordinates as fractions of the shape's box, so 0–1 or percentages. userSpaceOnUse uses the drawing's own coordinates — necessary when one gradient must span several shapes consistently. Same split applies to patternUnits / patternContentUnits, which is why patterns so often come out at the wrong scale: see colors-ch13.md.

Clip is binary, mask is graduated. <clipPath> cuts a hard edge from a shape outline. <mask> uses luminance, so white keeps, black hides, and grey fades — that is the one to reach for when a soft edge is wanted.

Markers need orient="auto-start-reverse" to point the right way at both ends of a line, and refX/refY set the pivot that lands on the vertex.

vector-effect="non-scaling-stroke" keeps stroke width constant when the graphic scales — usually what you want for icons and diagram rules.

Give ids meaning. skyFade survives being merged into a page that already has gradients; grad1 collides. Collisions matter because ids are document-global once the SVG is inlined.

In a component, generate the ids. A React or Vue icon rendered twice on one page emits every id twice — the gradient, the clip path, the <title> — and url(#x) then resolves to whichever instance came first. If that instance is hidden or unmounted, the others lose their paint. Use useId() in React (or a per-instance id in Vue) for every id inside the component, and build the references from it:

const id = useId();
const grad = `${id}-fill`;
// <linearGradient id={grad}> … <path fill={`url(#${grad})`} />

check_svg.py sees one file at a time, so it cannot catch this; it is on you.

Step 3 — Animate, when asked

Prefer CSS for transforms and opacity — it is GPU-composited and easy to scope. Reach for SMIL (<animate>) for things CSS cannot touch, such as a path's d attribute or individual gradient stops.

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; transform-origin: center; }

To rotate or scale an element about its own middle, set both transform-box: fill-box and transform-origin: center. On an SVG child element, transform-box defaults to view-box, so transform-origin: center alone means the centre of the whole canvas. A spinner that fills the canvas happens to work anyway; a gear in a corner orbits the middle of the picture instead of turning in place. (SMIL's <animateTransform type="rotate" values="0 cx cy; 360 cx cy"> takes the pivot explicitly, so it has no such trap.)

For a draw-on effect, put pathLength="1" on the path. Dash lengths are then fractions of the path, so stroke-dasharray: 1; stroke-dashoffset: 1 animated to 0 draws the whole stroke, with no need to measure the path in script.

Honour prefers-reduced-motion — animation that cannot be turned off is an accessibility problem, not a flourish. animation-ch07.md has the UI patterns; animation-ch08.md covers chart motion.

Step 4 — Make it embeddable and accessible

Give the graphic an accessible name unless it is purely decorative, in which case say so explicitly so a screen reader skips it rather than reading coordinates:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
     role="img" aria-labelledby="settings-title">
  <title id="settings-title">Settings</title>
  ...
</svg>
<!-- decorative instead: aria-hidden="true", and no title -->

Inline SVG when it needs CSS or scripting from the host page; <img src> when it is a standalone picture that should cache. web-ch40.md covers accessibility properly, web-ch08.md the embedding trade-offs.

Step 5 — Check it before handing it over

The checker ships with the skill (same placeholder rule as the library setup above):

python3 "${CLAUDE_SKILL_DIR}/scripts/check_svg.py" out.svg
python3 "${CLAUDE_SKILL_DIR}/scripts/check_svg.py" out.svg --optimize

This catches exactly the failures described at the top — unresolved url(#…) references, duplicate ids, malformed XML, a missing viewBox, a width/height ratio fighting the viewBox, absent accessible name, multiline text that will collapse onto one line, leftover Inkscape or Illustrator metadata, filter counts that will crawl on mobile. It exits non-zero when something is actually broken, so it is worth running even on markup you are confident about; the quiet failures are the whole reason it exists.

--optimize minifies through svgo (via npx if not installed globally) and reports the size saved. Use it when the user asked for optimization or when shipping an export that still carries editor cruft.

Fix what it reports before delivering, rather than passing the warnings along.

Delivery

Write the result to a file and show the path — SVG is something the user opens, and a wall of markup in the terminal is hard to judge. Include a short note on how to use it: the import line for a component, or the <img> tag for a file.

  • .svg — standalone, xmlns present, viewBox set, width/height at the viewBox ratio, and a <title> (or aria-hidden="true" if decorative).
  • HTML — full document with the SVG inline and a <style> block; required if CSS animation is part of the result.
  • React — props for size and color, spread the rest: {...props}. Use currentColor for fills so the icon inherits text color.
  • Vue — SFC with <template> and <style scoped>.

When the graphic is complex, comment the non-obvious paths. A d attribute with thirty coordinates is unreadable six months later, and a one-line comment saying what it draws is the difference between editable and disposable.

Related Skills