{"canonical_url":"https://engineer.company/glossary/svg/","content_markdown":"# SVG\n\n## What it is\n\nSVG, short for Scalable Vector Graphics, is a language for describing\ntwo-dimensional graphics as shapes rather than as a grid of pixels. The file\nsays what to draw: a circle here, a line from this point to that one, this\noutline filled in blue. The browser works out the pixels at whatever size the\ndrawing is shown, and that is where the scaling comes from: there are no pixels\nin the file to stretch.\n\nThe W3C defines it. Its latest version, SVG 2, is a Candidate Recommendation\nSnapshot dated 6 October 2026, expected to become a Recommendation no earlier\nthan 1 December 2026, and it builds on SVG 1.1 Second Edition. As the\nspecification sums itself up, SVG is built on XML, can combine vector shapes\nwith raster images, and takes styles, script and animation. A drawing can stand\nalone, sit inside an HTML page or be embedded in another XML language.\n\nThe vocabulary is small. Six basic shapes, `rect`, `circle`, `ellipse`, `line`,\n`polyline` and `polygon`, cover the simple cases, and a `path` draws anything\nelse from a short string of commands. `text` places real, selectable text, a\ngroup (`g`) lets several shapes share a style or a transform, and a gradient or\na pattern can paint a shape in place of a single colour. Filter effects, a\nchapter of SVG 1.1, now have a specification of their own. The initial coordinate\nsystem has its origin at the top left, x growing to the right and y growing\ndownwards.\n\nThe specification defines SVG in terms of a document object model rather than\none particular file format. A drawing can be a file of its own, served as\n`image/svg+xml` with the extension `.svg`, or it can be an `svg` element written\nstraight into an HTML page. A standalone file must declare the SVG namespace; in\nHTML the parser puts the elements in the right namespace by itself, so no\n`xmlns` attribute is needed.\n\nSVG is not a raster format like PNG or JPEG, which store a colour for every\npixel and go soft when enlarged. A photograph belongs in one of those. SVG suits\nwhat was drawn: icons, logos, diagrams, charts, maps and lettering. It can also\ncarry a raster image inside it, which is what the specification means by mixed\ngraphics.\n\n## Why it matters\n\nOne file serves every screen. An icon drawn once is sharp on an old monitor, on\na phone with several device pixels to every CSS pixel and on paper, with no\nseparate exports at each size to keep in step. Simple artwork also makes a small\nfile, because it describes a few outlines instead of storing thousands of\npixels, and the specification registers `.svgz` for an SVG file compressed with\ngzip.\n\nBecause the markup is text, it fits the way a team already works. A designer's\nexport can be read in a code review and compared line by line in version\ncontrol, and a script can generate a drawing from data, which is how many charts\nare made. Written inline in a page, the drawing's elements are part of the DOM:\nCSS styles them, a script can change them, and they follow hover, focus and the\nreader's colour scheme like everything else on the page.\n\nIt also carries meaning that a bitmap cannot. Text in an SVG stays text, and in\na processing mode that allows interaction the specification requires a browser\nto let the reader search for it and select it.\nA `title` element gives a drawing, or one part of it, an accessible name, and\nSVG 2 gives the `svg` element the implicit ARIA role `graphics-document`. A\nchart drawn in SVG can have labelled parts that a screen reader reaches one by\none; the same chart exported as a PNG is a single picture with a single text\nalternative.\n\n## What it looks like in practice\n\nHere is a small arrow in a rounded frame, written inline in an HTML page:\n\n```html\n\u003csvg viewBox=\"0 0 120 40\" width=\"240\" height=\"80\"\u003e\n  \u003ctitle\u003eNext step\u003c/title\u003e\n  \u003cg fill=\"none\" stroke=\"currentColor\" stroke-width=\"3\"\u003e\n    \u003crect x=\"2\" y=\"2\" width=\"116\" height=\"36\" rx=\"8\" /\u003e\n    \u003cpath d=\"M 20 20 H 92 M 80 10 L 100 20 L 80 30\" /\u003e\n  \u003c/g\u003e\n\u003c/svg\u003e\n```\n\n`viewBox` gives the drawing its own coordinates: four numbers for the left edge,\nthe top edge, the width and the height of the area to show, here 120 units wide\nand 40 high. `width` and `height` ask for 240 by 80 CSS pixels, so each unit is\ndrawn two pixels wide. Change those two numbers to 60 and 20 and the whole\ndrawing shrinks with them, line widths included, because nothing inside it is\nmeasured in pixels.\n\nThe group sets the paint once. Fill, stroke and stroke width are inherited, so\nthe frame and the arrow both take them from the `g`. The `rect` draws the frame,\nits corners rounded by `rx`. The path reads like instructions to a pen:\n`M 20 20` moves to a point without drawing, `H 92` draws a horizontal line to x\n= 92, the second `M` lifts the pen and puts it down at the top of the arrowhead,\nand the two `L` commands draw its two strokes. Upper-case commands take absolute\ncoordinates and lower-case ones relative, so the same path can be written as\n`m 20 20 h 72 m -12 -10 l 20 10 l -20 10`, each step measured from where the pen\nstopped.\n\n`currentColor` makes the stroke the value of the CSS `color` property, which an\ninline `svg` inherits from the HTML around it. Put the arrow in a link and it is\ndrawn in the link's colour; switch the page to a dark theme and it follows,\nwithout a second file. The `title` is not drawn. It gives the drawing its\naccessible name, and SVG 2 notes that browsers commonly show it as a tooltip\nwhen the pointer rests on the drawing.\n\nThe same drawing as a file of its own needs the namespace on its root element,\n`\u003csvg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 120 40\"\u003e`, and a page\nshows it with `\u003cimg src=\"/images/next.svg\" alt=\"Next step\"\u003e`. It is then a\nseparate document. CSS inheritance runs from parent to child, and the root\nelement of that document has no parent, so `currentColor` inside the file no\nlonger follows the text around the `img`. The `alt` attribute now supplies the\ntext alternative, and SVG 2 expects the browser to show the file in secure\nanimated mode, with no script and no external files.\n\n[This site's accessibility statement](/accessibility/) says its pages are written in\nHTML, CSS and SVG, with WAI-ARIA where HTML alone does not name something, and that\nevery page is complete without executable JavaScript. There, as in this article, SVG is\none of the languages a page is written in, next to its markup and its style sheets.\n\n## Where it goes wrong\n\n**A line drawing comes out as a solid shape.** The initial value of `fill` is\nblack, and the initial value of `stroke` is none. An open path meant as a line,\nsuch as an arrowhead or a tick, is filled as if its ends were joined, and with\nno stroke the lines themselves are not drawn at all. Set `fill=\"none\"` and a\n`stroke` on line art, once, on the group that holds it.\n\n**The icon disappears in dark mode.** Exported icons often carry a fixed colour,\n`fill=\"#1a1a1a\"`, which stays dark on a dark background. Such an attribute is\nalso the weakest style there is: SVG 2 gives presentation attributes a\nspecificity of zero, so a stray CSS rule elsewhere overrides it without anyone\nnoticing. Use `currentColor` for icons that sit in text, and set colours from\nCSS rather than in the markup.\n\n**The drawing will not scale, or scales wrongly.** Without `viewBox` the\ndrawing's units are the browser's pixels, so changing its width only crops or\npads it, and `preserveAspectRatio` is ignored altogether. A negative width or\nheight in `viewBox` is an error and the attribute counts as missing; a width or\nheight of zero disables rendering. Give every drawing a `viewBox`, and let\n`width` and `height`, or CSS, decide the size. The default, `xMidYMid meet`,\nkeeps the proportions and centres the drawing in its box.\n\n**Scaling is not the same as staying legible.** Nothing in a vector drawing\nstops it being shown at 16 pixels, but detail that reads well at 200 can merge\ninto a smudge there.\n[A portfolio entry on building this company's visual identity](/portfolio/built-the-visual-identity-from-2-drawings/)\ndescribes a vector cog drawn for the browser tab on the argument that a bold\nsilhouette survives 16 pixels. In that work, carried out in July 2026, the cog\nand the company mark were rendered side by side at 16, 32 and 48 pixels over\nlight and dark tab strips: the mark stayed recognisable, the cog washed out, and\nthe tab icon moved to the mark. Test a drawing at the smallest size it will be\nshown, on both kinds of background, and draw a simpler version for small sizes\nwhen it fails.\n\n**An uploaded SVG is a document, not a picture.** An SVG file can contain script\nand references to other files. Its media-type registration says plainly that\nscripting languages are executable content, and warns that maliciously\nconstructed XML entities, expanded over and over, can use up large amounts of\nmemory. How much of that runs depends on how the file is shown. SVG 2 expects an\n`object` element without sandboxing to run it in dynamic interactive mode, with\nscript, while `img` and CSS background images use secure animated mode, with no\nscript and no external references. Show SVG from outside sources only through\n`img`, serve uploads from a separate domain, or clean them against an allow-list\nof elements and attributes before they are stored.\n\n## Further reading\n\n- [Scalable Vector Graphics (SVG) 2](https://www.w3.org/TR/SVG2/)\n  — the W3C Candidate Recommendation Snapshot of 6 October 2026, with its\n  status, abstract and every chapter.\n- [Coordinate Systems, Transformations and Units](https://www.w3.org/TR/SVG2/coords.html)\n  — `viewBox`, `preserveAspectRatio` and the initial coordinate system.\n- [Paths](https://www.w3.org/TR/SVG2/paths.html)\n  — the path commands, absolute and relative coordinates, and what happens to\n  path data with an error in it.\n- [Painting: Filling, Stroking and Marker Symbols](https://www.w3.org/TR/SVG2/painting.html)\n  — `fill`, `stroke`, their initial values and the `currentColor` value.\n- [Conformance Criteria](https://www.w3.org/TR/SVG2/conform.html)\n  — the five processing modes and which one each way of embedding gets.\n- [Document Structure](https://www.w3.org/TR/SVG2/struct.html)\n  — `title` and `desc`, and the implicit ARIA roles of SVG elements.\n\n\u003chttps://engineer.company/glossary/svg/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"The W3C's language for vector graphics: viewBox and paths, colour from CSS, accessible names, what each way of embedding allows, and the usual traps.","formats":{"gemtext":"https://engineer.company/glossary/svg/index.gmi","gopher":"https://engineer.company/glossary/svg/gophermap","html":"https://engineer.company/glossary/svg/","json":"https://engineer.company/glossary/svg/index.json","markdown":"https://engineer.company/glossary/svg/index.md","pdf":"https://engineer.company/glossary/svg/index.pdf"},"kind":"page","language":"en","title":"What is SVG?","url":"https://engineer.company/glossary/svg/","version":1}