sabof
sabof

Reputation: 8192

Opening a SVG in a browser renders XML code instead of image

Several times I have opened SVG files located on various sites through a browser, and they were displayed as images.
Now, I copy this same SVG, I upload it to a remote host, and both Google Chrome and Firefox render XML code.
How do browsers determine whether to show an image or XML code?

Upvotes: 23

Views: 14315

Answers (2)

dev4life
dev4life

Reputation: 11394

As for your last question: How do browsers determine whether to show an image or XML code?

The answer lies in XML namespace. The XML namespace specified in an XML tag tells the user agent how to handle the tags. So if you have an <svg> without attribute xmlns="http://www.w3.org/2000/svg" then the browser will show text not the SVG rendered vector graphics.

Upvotes: 48

copy
copy

Reputation: 3372

You have to configure your server to send you svg files with Content-Type: image/svg+xml header. Here is an example on how to do this with Apache.

Upvotes: 2

Related Questions