After creating an SVG icon in Illustrator, I noticed that when I paste it inline and resize it in my HTML code, the image becomes blurry.
This issue seems to be happening across different browsers such as Firefox, Chrome, and Edge.
https://i.sstatic.net/6JyJF.png
body {
align-items: center;
display: flex;
height: 100vh;
justify-content: center;
width: 100vw;
}
svg {
height: 22px;
width: 22px;
}
svg:hover path {fill: tomato;}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M15.6 11.9H6v-1.2c0-.4-.3-.7-.7-.7H3.8c-.4 0-.7.3-.7.7v1.2H.4c-.1 0-.2.1-.2.2v.5c0 .1.1.2.2.2h2.7V14c0 .4.3.7.7.7h1.5c.4 0 .7-.3.7-.7v-1.2h9.5c.1 0 .2-.1.2-.2v-.5c.1-.1 0-.2-.1-.2zm-10.5 2h-1V11h1v2.9zM15.6 3.1H8V1.9c0-.4-.3-.7-.7-.7H5.8c-.4 0-.7.3-.7.7v1.2H.4c-.1 0-.2.1-.2.2v.5c0 .1.1.2.2.2h4.7v1.2c0 .5.3.8.7.8h1.5c.4 0 .7-.3.7-.7V4.1h7.6c.1 0 .2-.1.2-.2v-.6c0-.1-.1-.2-.2-.2zM7 5.1H6v-3h1v3zm8.6 2.4h-2.7V6.3c0-.4-.3-.7-.7-.7h-1.5c-.4 0-.7.3-.7.7v1.2H.4c-.1 0-.2.1-.2.2v.5c0 .1.1.2.2.2H10v1.2c0 .4.3.7.7.7h1.5c.4 0 .7-.3.7-.7V8.5h2.7c.1 0 .2-.1.2-.2v-.5c0-.2-.1-.3-.2-.3zm-3.7 2h-1v-3h1v3z"/></svg>
I've already attempted adding
orshape-rendering="geometricPrecision"
width="100%"
to thesvg
tag,shape-rendering="crispEdges"
topath
andtransform: translateZ(0);
to the svg style
but unfortunately, nothing seems to make the vector icon sharp.
Even adjusting the size of the icon doesn't improve the quality. For example:
svg {
height: 42px;
width: 42px;
}
the SVG icon remains blurry.
Any suggestions on how to achieve a scaled sharp vector image?
Check out the example code on CodePen: https://codepen.io/dash/pen/LYPxBPJ