Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create vector graphics in the browser with SVG

A step-by-step guide for incorporating SVG into Web pages and applications

Uche Ogbuji (uche@ogbuji.net), Principal Consultant, Fourthought Inc.
Photo of Uche Ogbuji
Uche Ogbuji is a consultant and cofounder of Fourthought Inc., a software vendor and consultancy specializing in XML solutions for enterprise knowledge management. Fourthought develops 4Suite, an open source platform for XML, RDF, and knowledge-management applications. Mr. Ogbuji is also a lead developer of the Versa RDF query language. He is a computer engineer and writer born in Nigeria, living and working in Boulder, CO. You can find more about Mr. Ogbuji at his Weblog Copia, or contact him at uche@ogbuji.net.

Summary:  Learn step-by-step how to incorporate Scalable Vector Graphics (SVG) into Web pages using real browser examples. SVG 1.1, an XML language for describing two-dimensional vector graphics, provides a practical and flexible graphics format in XML, despite the language's verbosity. Several browsers recently completed or announced built-in SVG support.

Date:  20 Jun 2006
Level:  Intermediate PDF:  A4 and Letter (445 KB | 33 pages)Get Adobe® Reader®

Activity:  13686 views
Comments:  

Before you start

Learn what to expect from this tutorial and how to get the most out of it.

About this tutorial

Scalable Vector Graphics (SVG) 1.1 is an XML language for describing two-dimensional vector graphics. Developed by the World Wide Web Consortium (W3C), it has the remarkable ambition of providing a practical and flexible graphics format in XML, despite the notorious verbosity of XML. SVG's feature set includes nested transformations, clipping paths, alpha masks, raster filter effects, template objects, and, of course, extensibility. SVG also supports animation, zooming and panning views, a wide variety of graphic primitives, grouping, scripting, hyperlinks, structured metadata, Cascading Style Sheets (CSS), a specialized Document Object Model (DOM) superset, and easy embedding in other XML documents. Overall, SVG has been one of the most widely and warmly embraced XML applications.

You can develop, process, and deploy SVG in many different environments, from mobile systems such as phones and Personal Digital Assistants (PDAs), to print environments. This tutorial focuses on SVG for Web development, offering step-by-step instruction for Web developers and designers to learn how to use SVG in practical Web sites. The lessons are built around examples that you can view and experiment with in your favorite browser. This tutorial doesn't go into a lot of detail about the SVG language. Instead, it provides a broad enough view of the language to guide you in deploying it on the Web.


Who should take this tutorial?

SVG is a technology positioned for many uses in the Web space. You can use it for presenting simple graphics (as with JPEG) or complex applications (as with Macromedia Flash). As such, it's an important weapon in every Web developer's and designer's arsenal. Programmers should take this tutorial if they deal with any Web applications. Web designers should take this tutorial to learn how to deploy efficient vector graphics on the Web.


Objectives

In this tutorial, you'll learn the basics of SVG in order to publish vector graphics on the Web using SVG. You'll learn how to render such images in a browser either stand-alone or embedded in XHTML.


Prerequisites

This tutorial assumes knowledge of XML, XML namespaces, CSS, and basic XHTML. Even though this tutorial focuses on SVG on the Web, it requires no prior knowledge of SVG and starts with the basics of the language. If you aren't familiar with XML, take the tutorial Introduction to XML. If you need to learn about XML namespaces, read the article Plan to use XML namespaces, Part 1. If you're not familiar with CSS, especially as used with XML, take the tutorial Display XML with Cascading Stylesheets: Use Cascading Stylesheets to display XML, Part 1: Basic techniques to present XML in Web browsers. This tutorial introduces the use of CSS to style XML in browsers. If you aren't familiar with XHTML, a good place to start is XHTML, step-by-step. You should also understand the basic mathematics of the two-dimensional rectilinear coordinate system, also known as the Cartesian coordinate system. You might remember this best from high school mathematics as how to specify points along X and Y axes.


System requirements

I highly recommend that you try out the examples in this tutorial. They only require a Web browser that supports SVG. Firefox 1.5 or later has such support built in, as does Opera 9. Safari has announced support for SVG in coming versions, but for now, the support is only available in nightly development snapshots where you have no guaranteed stability. Mac OS X users might want to try the Camino Web browser for SVG support. Microsoft® Internet Explorer users will require a plug-in such as the Adobe SVG Viewer. When showing browser output examples, I show screenshots of Firefox 1.5.0.2 on Ubuntu Linux®. Firefox is a popular Web browser available on Microsoft Windows®, Mac OS X, Linux, and other platforms. It is based on Mozilla's rendering engine.


About the examples in this tutorial

This tutorial features many examples of SVG files, either stand-alone or embedded in XHTML. All the files used in this tutorial are in the zip file, x-svggraphics-tutorial-files.zip. In this package, all files start with a prefix indicating what section they're covered in and what order of examples within the section. For example, the names of files from the first example in the third section start with eg_3_1.

Files that end with .svg are stand-alone SVG. Those that end with .xhtml are XHTML. A few files use other extensions such as .css for stand-alone CSS and .xsl for XSLT transform files.

I do take care to further list the example files in each panel and how each relates to the other, so if you follow along with the tutorial, you should be able to locate and experiment with the examples easily enough.

1 of 8 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Web development
ArticleID=128632
TutorialTitle=Create vector graphics in the browser with SVG
publish-date=06202006
author1-email=uche@ogbuji.net
author1-email-cc=dwxed@us.ibm.com