Menu

How to Center SVG Icons Without Changing Their viewBox
📰

How to Center SVG Icons Without Changing Their viewBox

DEV Community: frontend·Axialis Software·1 day ago
#vA1qTwPU
#devtofrontend#devto#dev#center#bookmark
Long article (340 words) — no AI summary yet.
Reading 0:00
15s threshold

Three icons can all be 24 × 24 and still sit differently in a toolbar. In our sample, a plus sat a little too far down and right, a folder sat up and left, and a bookmark sat up and right. We ran Center only on the three SVGs in IconVectors 2.30 and checked how far each drawing moved.

The batch result

File Move (x, y) Artwork size before and after viewBox before and after

add.svg (−3, −1) 16 × 16 0 0 24 24

folder.svg (+2, +1) 16 × 12 0 0 24 24

bookmark.svg (−2, +3) 12 × 16 4 6 24 24

All sizes and offsets are in SVG user units. Positive x moves right and positive y moves down.

Check the center of the bookmark

A viewBox gives you minX minY width height . For 4 6 24 24 , the center is (4 + 12, 6 + 12) , or (16, 18) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.