Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG does not display in img tag in Safari

Tags:

html

css

safari

svg

Simply put, I have an SVG graphic embedded in HTML that refuses to display in Safari (although it works fine in Chrome, Firefox, and other browsers).

I'm using the following markup to accomplish this:

<img alt="grapefruit logo" src="/assets/better-gf-logo_red.svg" />

Here is a live link to the the page where the SVG is not displaying. The fruit logo in the top left corner does not display in Safari: https://grapefruit.cs.rpi.edu/.

I have verified the following line is also present in my nginx mime.types:

 image/svg+xml                         svg svgz;

However, I know that the issue is probably not related to mime types, since the SVG doesn't appear in Safari on my development machine either (I tested several web servers). I have also tried displaying the SVG file itself in Safari, and it looks fine. The image element has the right size and box model, but it is not displaying any content.

like image 537
element119 Avatar asked Oct 07 '14 23:10

element119


People also ask

Why are my SVG images not showing?

Like the <img> method described above, inserting SVGs using CSS background images means that the SVG can't be manipulated with JavaScript, and is also subject to the same CSS limitations. If your SVGs aren't showing up at all, it might be because your server isn't set up properly.

Does SVG work in Safari?

SVG (basic support) is Fully Supported on Safari 12, which means that any user who'd be accessing your page through Safari 12 can see it perfectly.

Why is my SVG not showing up in HTML?

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.


1 Answers

Turns out that <img src="image.svg"> will not work in Safari, I tried using <object> and it worked. Give this a try: jsBin demo

<object
   type="image/svg+xml"
   height="70"
   width="150"
   data="/assets/better-gf-logo_red.svg">
</object> 

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object

like image 199
Roko C. Buljan Avatar answered Nov 17 '22 14:11

Roko C. Buljan