Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG images not loading on Chrome (sometimes)

Hi i have started converting a lot of my sites old image to SVG format and i cannot get them to display in the page.

The images do load if I open the image seperatly and then view the page after opening it. The SVG's are in the correct file path that I am referencing but nothing appears. Although on some refreshes it does appear.

<img class="padlock-img" src="content/img/cf/padlock.svg" alt="">
<img src="content/img/tips/progress.svg" alt="">
<img class="padlock-img" src="content/img/cf/padlock.svg" alt="">

Here are some of my examples

Example of one of the SVG's

Attempts

  1. I have attemted turning src into xlink:href and this stopped the images from loading at all

  2. I have tested this on 3 other browsers and the images load it is only happening on chrome on localhost and on file://

Any ideas on how to fix this?

like image 420
Kieranmv95 Avatar asked Oct 19 '15 13:10

Kieranmv95


People also ask

Why is SVG not showing up in Chrome?

Chrome browser doesn't support SVG format with <img src=””> tag anymore. Peoples are facing issues that they aren't able to see their images in Chrome browser because the images are in SVG format. So I found a solution to display SVG image in Chrome browser with <object> tag.

Why are my SVG images not showing?

If you are trying to use SVG like <img src="image. svg"> or as a CSS background-image , and the file is linked to correctly and everything seems right, but the browser isn't displaying it, it might be because your server is serving it with an incorrect content-type.

Does Google Chrome support SVG?

SVG (basic support) is Fully Supported on Google Chrome 94. If you use SVG (basic support) on your website or web app, you can double-check that by testing your website's URL on Google Chrome 94 with LambdaTest. The features should work fine.

Do any browsers not support SVG?

SVG (Scalable Vector Graphics) is officially supported by all main web browsers, including Internet Explorer.


2 Answers

When using SVG in Chrome, you need to make sure that your root tag has xmlns="http://www.w3.org/2000/svg"

Edit

I haven't been able to find the problem, but one alternative would be

<object data="yours.svg" type="image/svg+xml"></object>

this seems to do the trick for all browsers.

like image 140
Marco Aurélio Deleu Avatar answered Oct 06 '22 01:10

Marco Aurélio Deleu


For what it's worth I had an image like this

<img src="public/image/circles/circle.svg" class="circle_img" />

If you open the svg in an editor I changed

xlink:href="data:img/png;base64 to xlink:href="data:image/png;base64

like image 32
MomasVII Avatar answered Oct 06 '22 00:10

MomasVII