I'm looking for a way to have older browsers display a PNG image in place of an SVG as a fallback when detected. The logo for my site is currently in SVG but older browsers, specifically IE 8 and below won't render it. I already have the logo in PNG. What's the best way to execute this?
Thanks
PNGs and SVGs support transparency — so they're both excellent choices for online logos and graphics. It's worth noting that PNGs are one of the best choices for a raster-based transparent file. If you're working with pixels and transparency, PNGs are a better option than SVGs.
Include the Modernizer javascript in the head and make sure it includes SVG detection. When adding javascript in the head, type="application/javascript" will not work in older browsers so when including javascript use type="text/javascript" or don't use the type attribute at all.
To embed an SVG via an <img> element, you just need to reference it in the src attribute as you'd expect. You will need a height or a width attribute (or both if your SVG has no inherent aspect ratio). If you have not already done so, please read Images in HTML.
Use HTML conditional comments.
<!--[if lte IE 8]><img src="logo.png" /><![endif]-->
<!--[if gt IE 8]><img src="logo.svg" /><![endif]-->
<!--[if !IE]> --><img src="logo.svg" /><!-- <![endif]-->
http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx
If you're also looking for a way to handle this for browsers other than IE, you should check the user agent with javascript or php.
<object type="image/svg+xml" data="image.svg">
<img src="image.png" alt="image"/>
</object>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With