Questions tagged [svg]

Scalable Vector Graphics (SVG) is an XML-based two-dimensional vector graphics format that can also be used in HTML. Do not add this tag just because your project uses SVG. Instead, add the tag if your question is either about SVG, or closely related to it, like how to achieve something with SVG.

Scalable Vector Graphics

Scalable Vector Graphics (SVG) is a markup language for describing two-dimensional images, animations, and applications. SVG is also a set of related graphics script interfaces. The SVG format differs from raster formats by encoding graphics predominately using math and matrix transformations, which allows SVG output to be resolution independent. While SVG is an -based format, it can be embedded within using HTML parsing rules.

The current version is SVG 1.1 (Second Edition), released in 2011. SVG 1.2 is unpublished, the latest version is from 2005. SVG 2 is under active development.

Example SVG file

The following shows a fuchsia-coloured circle having a thick black border situated above text rotated by 15 degrees.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" version="1.1">
  <style type="text/css">
    circle { fill: fuchsia; stroke: black; stroke-width:2 }
    text { font: 12pt sans-serif }
  </style>
  <circle cx="30" cy="20" r="10"/>
  <text x="10" y="40" transform="rotate(15)">Rotated text</text>
</svg>​

Rendered result

Example SVG Scene

Useful links

SVG Editors

SVG Manipulation Libraries

38473 questions
669
votes
16 answers

Do I use , , or for SVG files?
Should I use , , or for loading SVG files into a page in a way similar to loading a jpg, gif or png? What is the code for each to ensure it works as well as possible? (I'm seeing references to including the mimetype or pointing…
artlung
  • 30,810
  • 16
  • 66
  • 118
591
votes
13 answers

What are the different usecases of PNG vs. GIF vs. JPEG vs. SVG?

When should certain image file types be used when building websites or interfaces, etc? What are their points of strength and weakness? I know that PNG & GIF are lossless, while JPEG is lossy. But what is the main difference between PNG & GIF? Why…
Faruz
  • 9,691
  • 10
  • 44
  • 65
564
votes
24 answers

How to change the color of an svg element?

I want to use this technique and change the SVG color, but so far I haven't been able to do so. I put this in the CSS, but my image is always black, no matter what. My code: .change-my-color { fill: green; }
Barbara
  • 7,174
  • 5
  • 29
  • 43
501
votes
8 answers

HTML5 Canvas vs. SVG vs. div

What is the best approach for creating elements on the fly and being able to move them around? For example, let's say I want to create a rectangle, circle and polygon and then select those objects and move them around. I understand that HTML5…
verdy
  • 6,807
  • 6
  • 23
  • 27
498
votes
24 answers

img src SVG changing the styles with CSS

html Logo css .logo-img path { fill: #000; } The above svg loads and is natively fill: #fff but when I use the above css to try change it to black it doesn't change, this is my first time playing with…
ngplayground
  • 16,883
  • 32
  • 91
  • 160
459
votes
18 answers

How to convert a SVG to a PNG with ImageMagick?

I have a SVG file that has a defined size of 16x16. When I use ImageMagick's convert program to convert it into a PNG, then I get a 16x16 pixel PNG which is way too small: convert test.svg test.png I need to specify the pixel size of the output…
kayahr
  • 18,296
  • 27
  • 93
  • 139
456
votes
6 answers

SVG fill color transparency / alpha?

Is it possible to set a transparency or alpha level on SVG fill colours? I've tried adding two values to the fill tag (changing it from fill="#044B94" to fill="#044B9466"), but this doesn't work.
Ollie Glass
  • 17,505
  • 18
  • 65
  • 98
452
votes
18 answers

How to change color of SVG image using CSS (jQuery SVG image replacement)?

This is a self Q&A of a handy piece of code I came up with. Currently, there isn't an easy way to embed an SVG image and then have access to the SVG elements via CSS. There are various methods of using JS SVG frameworks, but they are overly…
Drew Baker
  • 13,308
  • 12
  • 50
  • 90
427
votes
8 answers

SVG drop shadow using css3

Is it possible to set drop shadow for an svg element using css3 , something like box-shadow: -5px -5px 5px #888; -webkit-box-shadow: -5px -5px 5px #888; I saw some remarks on creating shadow using filter effects. Is there an example of using css…
bsr
  • 52,180
  • 78
  • 198
  • 296
376
votes
23 answers

Detect iPad Mini in HTML5

Apple's iPad Mini is a smaller clone of the iPad 2 in more ways than we'd want. In JavaScript, the window.navigator object exposes the same values for the Mini and iPad 2. My tests so far to detect the difference have not lead to success. Why is…
Martin Kool
  • 4,062
  • 4
  • 23
  • 35
343
votes
16 answers

Modify SVG fill color when being served as Background-Image

Placing the SVG output directly inline with the page code I am able to simply modify fill colors with CSS like so: polygon.mystar { fill: blue; }​ circle.mycircle { fill: green; } This works great, however I'm looking for a way to modify…
Joe
  • 4,315
  • 2
  • 27
  • 39
333
votes
10 answers

Inline SVG in CSS

Is it possible to use an inline SVG definition in CSS? I mean something like: .my-class { background-image: ...; }
akaRem
  • 6,200
  • 3
  • 25
  • 40
323
votes
10 answers

Convert SVG to image (JPEG, PNG, etc.) in the browser

I want to convert SVG into bitmap images (like JPEG, PNG, etc.) through JavaScript.
Zain
  • 4,605
  • 11
  • 30
  • 31
299
votes
8 answers

Is there a way to use SVG as content in a pseudo element :before or :after

I want to place some SVG images before some selected elements. I am using jQuery but that is irrelevant. I would like to have the :before element to be as: #mydiv:before { content: ''; display: block; width: 22px; …
Sunny
  • 6,849
  • 6
  • 38
  • 69
292
votes
15 answers

jQuery SVG, why can't I addClass?

I am using jQuery SVG. I can't add or remove a class to an object. Anyone know my mistake? The SVG: The jQuery that won't add the class: $(".jimmy").click(function() { …
Don P
  • 49,839
  • 95
  • 259
  • 394
1
2 3
99 100