Transparent background is trimmed in SVG export


When I export SVG in Sketch 98.3, the transparent background is trimmed (deleted) from images. for example, I have several icon symbols in size of 16x16 but exported SVGs are not 16x16 pixels.
The preview shows the correct image but the exported icon is trimmed!

Here is an example of issue:

Hi @Taha,

Can you share a sample file to review this in detail? I just did some exports with 98.3 and the transparent space is kept. I exported a symbol source, a symbol instance and a svg layer with a background and all three kept the space.

Here’s the file if you want to take a look
SVG Exports.sketch (17.4 KB)

Hi @dfmedrano

Thank you for following up. I found Sketch exported svg properly but when I imported them again to Sketch, the background was trimmed.

Here is your file with imported svg:
SVG Exports-1.sketch (26.5 KB)

Also, I found that if you try to drag the file from the preview to an artboard, png is generated instead of svg.

Hey, @Taha thanks for the update!

I’ll check about the trimming of transparent space when you reimport an SVG exported from Sketch that has some transparent space.

About the bitmap layer that’s generated when you drag and drop from the Preview panel, this is the expected behavior; after all, the original layer is still on your file and is vector based (or is an SVG itself), so you can make all the edits and have the SVG format by completing the export process.

I’m aware this may not be the expected outcome and I wanted to ask if this is impacting your workflow.

Thanks for considering the issue carefully.

The bitmap layer generated from the preview doesn’t impact my workflow so it is not very important but trimming a transparent background makes some workflow difficult.
I consider it more carefully and find that it happens for every svg with transparent not just svg generated by Sketch.
If I want to use several svg files created by other apps and designers, I should put them in a transparent rectangle to make them the same size which is very time-consuming.

for more consideration, I created an svg by the Curve (Vectornator) app and opened it in Chrome and Sketch.

Here I open it in Chrome. The size is correctly 24x24. Notice the “view box” highlighted in the right column.

Here is Sketch. The size is 12x13.86. Apparently, Sketch ignores the “view box” property in svg files!

So maybe this is a better title for this issue: “Sketch ignore view box property in svg files”

Hi @Taha, I checked why space is trimmed and it’s because Sketch groups always wrap to its contents. When you import SVG content into Sketch it’s always imported in a group and thus, it wraps to its contents because the viewbox attribute is not mapped as a new layer that would keep the spacing.

Of course, I can clearly see your point and I’ve documented this as a feature request.

Hi @dfmedrano I’m also experiencing this problem when importing PNGs into Sketch. My PNGs need to have a specifically defined border size to them (which is, say, 10px of transparent space around the content), but Sketch is trimming that off, making it really hard to use. Is this the same issue you’re describing above?

Hi @JoeWhittle ,

Thanks for reporting this. I tested on version 98.3 and PNGs are imported as expected, with the transparent space from the original image. Here’s a video of the test I made. Please take a look and let me know if I’m missing anything.