Browser Support: Standoffish or Integrated

Not all browsers support SVG equally, and Internet Explorer doesn't support SVG at all. Of the other popular browsers, most will process standalone SVG files but differ in how SVG is integrated directly into web pages.

The Hello, World example in Chapter 7 was a standalone SVG document, saved with an .svg extension and served with a MIME type of image/svg+xml. These separate SVG files can be accessed directly or incorporated into a web page using either the embed or object element or via an iframe. Of the three, embed is a deprecated element, and iframe isn't XHTML Strict compliant, though it does validate with XHTML Transitional. The only element that's valid with XHTML 1.0 Strict is the object element. Since this element is supported by Firefox 2.x and 3, Safari 3.x, and Opera 9.x, that's the only element I'll use to demonstrate incorporating a separate SVG file into a web page.

SVG Through the object Element

Once you have a valid, working SVG file (tested by opening it directly into a browser that supports SVG), you can then incorporate it into a web page.

To get things started, Example 7-1 contains a web page with an SVG file incorporated into the page through an object element. The object is modified through a style attribute, which sets the width and height and adds a border. The external SVG file is the second Hello World example from Chapter 6.

Example 7-1. Using the object element to embed an external SVG file

<!DOCTYPE html PUBLIC "-//W3C//DTD ...

Get Painting the Web now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.