Creating SVG Files
One of the great things about scalable vector Graphics ( SVG ) is that you can create them in a variety of graphics programs. besides, because the file is based in XML, you can roll your sleeves up and edit the file directly or programmatically via JavaScript
Tools to Create SVG Files
Graphical Editors
Examples of common graphic editors you can use to make SVG files .
- Adobe Illustrator
- Sketch
- Inkscape
Inkscape is free for use and might be a adequate option if you do n’t have access to Illustrator or Sketch. There is a comprehensive examination tutorial on-line for using Inkscape. See the incision below for more information on creating SVG files in Adobe Illustrator .
Text Editors and JavaScript
You can besides create and edit SVG files by just opening a text editor program and creating the files.
SVG graphics should start with the svg
component :
Between the svg
component you can add in other svg shapes or paths such as circle
, rect
, ellipse
or path
.
You can besides use several different JavaScript libraries to draw SVG files and manipulate them on your vane pages. Examples of these libraries are :
There are besides many other options available for JavaScript libraries to manipulate SVG files .
Creating SVG files in Adobe Illustrator
possibly the easiest means to create sophisticate SVG files is to use a tool that you are probable already familiar with : Adobe Illustrator. While it ‘s been possible to make SVG files in Illustrator for quite some prison term, Illustrator CC 2015 added and streamlined the SVG features. These changes include different exporting options, clean generated SVG code, and ability to copy and paste SVG files into a text editor program .
SVG is a native file format in Adobe Illustrator. Start by creating an example. here is an example of a bear font :
A simple illustration in Illustrator of a bear face.
You can download the original Adobe Illustrator file besides .
Exporting the SVG file
You can use the Save As feature to save to the SVG format directly. Choose File > Save As from the Menu Bar .
You can create a file and then choose File > Save As to save the file .
In the save window, change the Format to SVG (svg) and then click Save .
Change the format to SVG.
SVG Options
After clicking save an SVG Options window open. This window offers a kind of options to fuss with. For the most depart, the default options are o .
- SVG Profiles: Leave SVG 1.1 selected
- Fonts: These two options only matter if you have text in your graphic. Generally you should leave your type as SVG instead of converting it to outlines. This improves accessibility. Leave these options as the default.
- Image Locations: This only matters if your graphic includes any raster image files in it. Generally, this will not be applicable when creating graphics for the web. Include raster graphics in your SVG kind of defeats the purpose of using them in the first place.
- Preserve Illustrator Editing Capabilities: You should leave this box unchecked. You can always save an ai file for later editing. You will also be able to open the SVG in Illustrator. Checking Preserving editing capabilities will add unnecessary information to your file, making it harder to manipulate in an editor and increasing the size.
Advanced Options
This button provides several “ advanced ” option for your SVG file.
- CSS Properties: This will affect how the styled properties are written in your SVG file. While all four options will work, usually either Style Elements or Style Attributes will be the best options. For a complete comparison of the options see Demystifying Adobe Illustrator’s Advanced Options for SVG Work
- Include unused graphical styles: Leave unchecked
- Decimal Places: This will affect the precision of the numbers in your graphics. More decimal places will result in a slightly larger file size while using few decimal places may result in a loss of detail. Keep in mind that generally the effects of this setting is going to be very subtle.
- Output fewer elements:Leave checked
- Use element for Text on Path: Leave checked
- Include Slicing Data: Leave unchecked
- Include XMP: Leave unchecked
- Responsive: You should check this box to allow your graphic to resize responsively. Without this box checked, Illustrator will add width and height attributes to the
svg
element in your file. You could, of course, always delete those attributes later.
SVG Code Button
You can press this button any time to generate the text of the SVG file. It will automatically open in the default text editor program. You can use this to see what your final file will look like or even copy and paste the text from it .
We ‘ll save our bear face graphic using the the Style Elements option in the CSS Properties drop down. All the other options are the default .
Change the CSS Properties to Style Elements.
This will give us the follow SVG file, which we can open in a text editor program .
Removing the XML Declaration and Comments
When Illustrator generates your SVG file, it adds two extra lines to the top of the file .
The beginning line is the XML resolution. If you are including your SVG file inline with your HTML, you can safely delete this line. however, if you do not delete it, it will not hurt anything .
The second line is precisely an HTML comment added by Illustrator to include information about how the graphic was created. This line should be deleted to reduce the concluding file size .
Using Layers In Illustrator Effectively
While the above file will work just ticket, we can actually utilize the layers in Illustrator to add names and groups to our concluding SVG file. The layers and groups in Illustrator will be translated into classes and gravitational constant elements in the file and will help us style out graphics with CSS .
In the original bear charge, we did n’t name any of the layers or group similar shapes. When we view the file, it is hard to tell which shapes are what. They have foreign ids like XMLID_3 .
None of the layers are named or grouped.
now I ‘ve given each sublayer a name. Each of the names will be translated into an id
assign in our file. I ‘ve besides organized the layers into logical groups. Each group will be translated into a g
chemical element .
Now all of our layers are named and grouped logically.
now our export SVG file is a lot more clear and ready to be styled if we want to .
precisely how you choose to organize your file into groups will depend on your final goal. If you ‘re doing any kind of animation or styling via CSS or JavaScript, it ‘s helpful to have your shapes organized into groups that can be styled or animated in concert .
Resources for using Illustrator Layers
by and large, the layers work similarly to how they work in Photoshop. Below are some resources :
Read more: Microwave Scrambled Eggs
Setting the Artboard Bounds
Your actual graphic probably will not fill the integral Artboard ( white setting ) in Illustrator. If you export your SVG charge without addressing this, your file will end up including all that extra outer space. While this will not affect the file size, it will affect how your graphic displays in a browser. Before saving your graphic, you show make indisputable that you fit the Artboard to the artwork .
In the Menu Bar, go to Object > Artboards > Fit to Artwork Bounds .
After doing this, our bear charge looks like this :
Our graphic after we fit the Artboard to the artwork.
Tips to Consider When Creating Your SVG
- Always name and group your layers.
- Try to keep your graphics as simple as possible. Remember that not everything Illustrator is capable of can be rendered in SVG.
- Use the simple shape tools wherever possible. Shapes like rectangles, circles, ellipses, polygons and lines all have native counterparts in SVG.
- Remember when you are drawing your SVG that each shape, line, gradient, etc. will be represented in the SVG syntax. SVG excels at representing simple shapes, lines and text. However, if your graphic becomes too complicated (too many complicated paths or textures), you might find that your resulting SVG file is too large.