Websites and web tools
Hidden Features Worth Knowing in SVG Editing
SVG is a text format for vector graphics, which makes it ideal for a shop logo, service icons or a simple diagram of where to find a tire placard. Many people only ever export an SVG from a design app and upload it. Opening the file in a text editor reveals features that make graphics smaller, sharper and easier to restyle.
The viewBox does the scaling
The viewBox attribute sets the internal coordinate system, for example 0 0 24 24. If you remove fixed width and height attributes and keep the viewBox, the graphic scales cleanly to whatever size CSS gives it. This is how one logo file can serve the header, the footer and a favicon-sized badge.
currentColor for icons that follow the text
Set fill="currentColor" on an icon's shapes and the icon takes the text colour of its surroundings. Your phone and map icons then change colour on hover and in dark mode with no extra files. It works for inline SVG; an SVG loaded through an image tag cannot see the page's CSS.
symbol and use for icon sets
Define each icon once inside a symbol element with its own id and viewBox, then draw it anywhere with a use element that points at that id. A services page with a dozen icons repeated in several places then carries each drawing only once.
Path precision and file size
Design apps often export coordinates with many decimal places. On screen, one or two decimals are almost always enough.
Other features hiding in the file
| Feature | What it does | Practical use |
|---|---|---|
title element | Gives the graphic an accessible name | Screen readers announce your logo as your business name |
preserveAspectRatio | Controls fit when the box shape differs from the viewBox | Stop a wide banner graphic from squashing |
stroke-linecap and stroke-linejoin | Round or square line ends and corners | Consistent look across line icons |
vector-effect="non-scaling-stroke" | Keeps line width constant as the graphic scales | Thin outlines on a scalable diagram |
pattern | Fills a shape with a repeating tile | Simple tread or texture effects without an image |
Clean-up steps before publishing
- Open the file in a text editor and look at its size and structure.
- Remove editor metadata, comments and hidden layers.
- Round coordinates to one or two decimals and compare the look.
- Keep the viewBox and add a title element.
- Run it through an SVG optimizer, then check the result visually.
- Test it at the smallest and largest sizes you will use.
Safety note on user uploads
SVG files can contain scripts. If your site lets customers upload images, such as photos of damage for a quote, do not accept SVG from untrusted users, or sanitise it on the server. Serving an uploaded SVG from your main domain can expose visitors to script attacks.