Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v3
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm exec lint-staged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pnpm preview # preview the static build

Any push to `main` triggers `.github/workflows/deploy.yml`, which builds the static site and deploys it to GitHub Pages (source: GitHub Actions).

The site is served at <https://svgforge.github.io/>.
The site is served at <https://svgforge.github.io/>.
2 changes: 1 addition & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
"$schema": "https://biomejs.dev/schemas/2.6.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"check": "astro check",
"lint": "biome ci .",
"preview": "astro preview",
"astro": "astro"
"astro": "astro",
"prepare": "husky"
},
"dependencies": {
"@astrojs/sitemap": "^3.7.4",
Expand All @@ -25,6 +26,11 @@
"devDependencies": {
"@astrojs/check": "^0.9.12",
"@biomejs/biome": "^2.6.4",
"husky": "^9.1.7",
"lint-staged": "^17.6.0",
"typescript": "^6.0.3"
},
"lint-staged": {
"*": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true"
}
}
39 changes: 33 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions src/content/blog/custom-icon-sets/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---

title: Create Your Own Icon Sets for the SVG Forge Icon Manager
pubDate: 2026-09-15
tags:
- tips
- svg
- tips
- svg

---

The **SVG Forge Icon Manager** is a Gutenberg plugin for WordPress: an "SVG Icon" block inserts icons via `<use>` from a central SVG sprite file into your content. The plugin is deliberately *not* an icon collection with an import UI — every icon must exist as a `<symbol>` element in a sprite file that you build, maintain, and version yourself.
The **SVG Forge Icon Manager** is a Gutenberg plugin for WordPress: an "SVG Icon" block inserts icons via `<use>` from a central SVG sprite file into your content. The plugin is deliberately _not_ an icon collection with an import UI — every icon must exist as a `<symbol>` element in a sprite file that you build, maintain, and version yourself.

This article shows you how to create your own icon set: create a folder full of SVG files, build them with [svgforge-cli](https://github.com/svgforge/svgforge-cli/) into a sprite file in one line, and hook it into the plugin. Including the **directory-marker trick**, which turns your subfolders into filter groups in the icon picker automatically.

Expand Down Expand Up @@ -71,10 +73,10 @@ svgforge --symbol --dest=out 'assets/./**/*.svg'

The trick is the `./` right in the middle of the glob: it is the **directory marker**. Everything before it is only the base from which the icon ID is calculated. Without the marker, the base folder name would bleed into every ID:

| Glob | Icon ID | Group |
|---|---|---|
| `assets/**/*.svg` | `assets--actions--add_circle` | `assets` (single, useless group) |
| `assets/./**/*.svg` | `actions--add_circle` | `actions` |
| Glob | Icon ID | Group |
| ------------------- | ----------------------------- | -------------------------------- |
| `assets/**/*.svg` | `assets--actions--add_circle` | `assets` (single, useless group) |
| `assets/./**/*.svg` | `actions--add_circle` | `actions` |

With `./`, you get compact IDs like `actions--add_circle` from `assets/actions/add_circle.svg`. The base name `assets` disappears, and each subfolder level becomes a `--` segment — the picker turns it into the group filter. Without the marker, all icons would share the identical `assets--` prefix and the filter would be useless.

Expand All @@ -88,21 +90,19 @@ After the run, the finished sprite lives at `out/symbol/sprite.svg`. If you pref

```json
{
"dest": "./dist/material",
"shape": {
"transform": [
{
"svgo": {
"plugins": [
{ "name": "removeAttrs", "params": { "attrs": "fill" } }
]
}
}
]
},
"mode": {
"symbol": { "sprite": "sprite.svg", "render": { "css": false } }
}
"dest": "./dist/material",
"shape": {
"transform": [
{
"svgo": {
"plugins": [{ "name": "removeAttrs", "params": { "attrs": "fill" } }]
}
}
]
},
"mode": {
"symbol": { "sprite": "sprite.svg", "render": { "css": false } }
}
}
```

Expand Down Expand Up @@ -146,4 +146,4 @@ The plugin distinguishes automatically: multicolored sets (like Tango) keep thei

A custom icon set is therefore: a folder with SVG files, a build command with the `./` directory marker, and an upload (or a filter) in the plugin. The subfolders automatically become filter groups in the picker. The structure and configs from [svgforge/default-icons](https://github.com/svgforge/default-icons) serve as a starting point.

**Tip:** If you work with a CI/CD pipeline, you can add your icons as individual SVGs to your theme. A GitHub workflow generates the `sprite.svg` during the build — the installable ZIP then contains the theme including the generated `sprite.svg`.
**Tip:** If you work with a CI/CD pipeline, you can add your icons as individual SVGs to your theme. A GitHub workflow generates the `sprite.svg` during the build — the installable ZIP then contains the theme including the generated `sprite.svg`.
66 changes: 34 additions & 32 deletions src/content/blog/defs-vs-symbol-sprites.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
---

title: defs vs symbol sprites
description: When should you choose <defs> and when <symbol>? Both are inline <use> sprite techniques — this post explains the differences based on the SVG spec.
pubDate: 2026-03-10
tags:
- tutorial
- svg
- tutorial
- svg

---

When should you choose `<defs>` and when `<symbol>`?

This post compares both inline sprite approaches — and yes, the two are *not*
This post compares both inline sprite approaches — and yes, the two are _not_
interchangeable. `<defs>` and `<symbol>` are siblings from the same family of
[structural elements](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element#structural_elements),
but they serve different purposes, defined by the specification itself.
Expand All @@ -20,16 +22,16 @@ Both elements have been part of SVG since the very beginning and are covered in
both the [SVG 1.1 spec](https://www.w3.org/TR/SVG11/struct.html) and the
[SVG 2 draft](https://www.w3.org/TR/SVG2/struct.html):

| Element | SVG 1.1 | SVG 2 | MDN reference |
| --- | --- | --- | --- |
| `<defs>` | [The defs element](https://www.w3.org/TR/SVG11/struct.html#DefsElement) | [The defs element](https://www.w3.org/TR/SVG2/struct.html#DefsElement) | [MDN `<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/defs) |
| Element | SVG 1.1 | SVG 2 | MDN reference |
| ---------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `<defs>` | [The defs element](https://www.w3.org/TR/SVG11/struct.html#DefsElement) | [The defs element](https://www.w3.org/TR/SVG2/struct.html#DefsElement) | [MDN `<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/defs) |
| `<symbol>` | [The symbol element](https://www.w3.org/TR/SVG11/struct.html#SymbolElement) | [The symbol element](https://www.w3.org/TR/SVG2/struct.html#SymbolElement) | [MDN `<symbol>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/symbol) |
| `<use>` | [The use element](https://www.w3.org/TR/SVG11/struct.html#UseElement) | [The use element](https://www.w3.org/TR/SVG2/struct.html#UseElement) | [MDN `<use>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/use) |
| `<use>` | [The use element](https://www.w3.org/TR/SVG11/struct.html#UseElement) | [The use element](https://www.w3.org/TR/SVG2/struct.html#UseElement) | [MDN `<use>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/use) |

## What `<defs>` is

The specification describes `<defs>` as a **reference container**: a place to
store objects that are *not rendered directly* but **referenced from
store objects that are _not rendered directly_ but **referenced from
elsewhere**. Elements inside `<defs>` have an implicit `display:none` — they
exist in the document tree, but nothing is drawn until something points at
them via an IRI reference (`url(#id)`, `<use href="#id">`, …).
Expand All @@ -46,7 +48,7 @@ them via an IRI reference (`url(#id)`, `<use href="#id">`, …).
</svg>
```

That is the *primary* use case of `<defs>`: it hosts **helper objects**
That is the _primary_ use case of `<defs>`: it hosts **helper objects**
(gradients, patterns, filters, masks, markers, clip paths) that other
elements pull in. It is not designed as an "icon library" element — it
simply happens to work for that, because any element, including an `<svg>`
Expand All @@ -55,7 +57,7 @@ with an ID, can be placed inside and later cloned via `<use>`.
## What `<symbol>` is

`<symbol>` is fundamentally different: it is a **graphical template object**
that is *instantiated* by `<use>`.
that is _instantiated_ by `<use>`.

> The `symbol` element is used to define graphical template objects which
> can be instantiated by a `use` element.
Expand All @@ -81,7 +83,7 @@ This matters because of how `<use>` renders its target:
> — [SVG 1.1, 5.6](https://www.w3.org/TR/SVG11/struct.html#UseElement)

When a `<use>` instantiates a `<symbol>`, the symbol becomes an inner
`<svg>` — and that inner `<svg>` *inherits the symbol's `viewBox`*. The
`<svg>` — and that inner `<svg>` _inherits the symbol's `viewBox`_. The
icon thus gets proper, aspect-ratio-aware scaling for free. You do **not**
need to repeat the `viewBox` on the `<use>` wrapper:

Expand Down Expand Up @@ -109,15 +111,15 @@ A `<use>` can reference either
(`<use href="#id">`) or
[an external SVG file](https://caniuse.com/mdn-svg_elements_use_external_uri)
(`<use href="sprite.svg#id">`). Both work for `<defs>` and `<symbol>` alike —
*because* both are just ID-targets.
_because_ both are just ID-targets.

There is a catch, though: an external `<use>` reference creates a **separate
DOM** (see [CSS-Tricks, "SVG use with external reference"](https://css-tricks.com/svg-use-with-external-reference-take-2)).
That means:

- you can style the `href` target from outside CSS, but **not** individual
shapes inside the sprite (`#icon .path-1` won't match),
- references *inside* the sprite file (e.g. a gradient `fill="url(#grad)"`)
- references _inside_ the sprite file (e.g. a gradient `fill="url(#grad)"`)
may not resolve in Chrome when the sprite is loaded externally.

Whether you inline the sprite or fetch it externally, `<defs>` and
Expand Down Expand Up @@ -158,17 +160,17 @@ Enable them in your config and get both variants:

```json
{
"dest": "out",
"mode": {
"defs": {
"sprite": "svg/sprite.defs.svg",
"example": true
},
"symbol": {
"sprite": "svg/sprite.symbol.svg",
"example": true
}
}
"dest": "out",
"mode": {
"defs": {
"sprite": "svg/sprite.defs.svg",
"example": true
},
"symbol": {
"sprite": "svg/sprite.symbol.svg",
"example": true
}
}
}
```

Expand All @@ -188,11 +190,11 @@ over `<defs>`:
2. **Scaling semantics built in.** `viewBox` + `preserveAspectRatio` even let
a single icon render at different sizes and aspect ratios from one
definition — impossible with a plain `<g>` or `<svg>` in `<defs>`.
3. **Clearer semantics.** `<symbol>` is *made for* reusable graphical
3. **Clearer semantics.** `<symbol>` is _made for_ reusable graphical
templates; `<defs>` is meant for helper objects.

**Use `<defs>`** when your icons are not self-contained units but *parts that
other icons reference* — shared gradients, filters, masks, or clip paths that
**Use `<defs>`** when your icons are not self-contained units but _parts that
other icons reference_ — shared gradients, filters, masks, or clip paths that
several symbols pull in. In a hybrid setup it is perfectly normal to wrap every
icon in `<symbol>` and put the shared helpers in a `<defs>` above them.

Expand All @@ -209,9 +211,9 @@ identifiers are the way to go — which is what svgforge's
[`view`](https://css-tricks.com/svg-fragment-identifiers-work/) modes produce
(`<img src="sprite.stack.svg#id">`). A quick decision guide:

| Need | Mode |
| --- | --- |
| Inline icons, styleable with CSS/`currentColor`, reusable many times | `symbol` (or `defs`) |
| Need | Mode |
| --------------------------------------------------------------------- | -------------------------------- |
| Inline icons, styleable with CSS/`currentColor`, reusable many times | `symbol` (or `defs`) |
| Stylesheet-driven icons with cacheable, externally referenced sprites | `symbol` + `render: {css: true}` |
| `<img>` or `background-image` icons | `stack` |
| Foreground images with browser-native slicing | `view` |
| `<img>` or `background-image` icons | `stack` |
| Foreground images with browser-native slicing | `view` |
Loading
Loading