Spunk Autos

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

FeatureWhat it doesPractical use
title elementGives the graphic an accessible nameScreen readers announce your logo as your business name
preserveAspectRatioControls fit when the box shape differs from the viewBoxStop a wide banner graphic from squashing
stroke-linecap and stroke-linejoinRound or square line ends and cornersConsistent look across line icons
vector-effect="non-scaling-stroke"Keeps line width constant as the graphic scalesThin outlines on a scalable diagram
patternFills a shape with a repeating tileSimple tread or texture effects without an image

Clean-up steps before publishing

  1. Open the file in a text editor and look at its size and structure.
  2. Remove editor metadata, comments and hidden layers.
  3. Round coordinates to one or two decimals and compare the look.
  4. Keep the viewBox and add a title element.
  5. Run it through an SVG optimizer, then check the result visually.
  6. 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.