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, 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

43459 questions
1136
votes
43 answers

How can I 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 use this in the CSS, but my image is always black, no matter what. My code: .change-my-color { fill: green; }
Barbara
  • 12,908
  • 6
  • 32
  • 43
760
votes
19 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
  • 33,305
  • 16
  • 69
  • 121
723
votes
27 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
  • 20,365
  • 36
  • 94
  • 173
602
votes
14 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,909
  • 10
  • 48
  • 66
578
votes
20 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
  • 20,913
  • 29
  • 99
  • 147
539
votes
10 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…
Agustinus Verdy
  • 7,267
  • 6
  • 26
  • 28
505
votes
7 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
  • 19,455
  • 21
  • 76
  • 107
505
votes
24 answers

How to modify the fill color of an SVG image 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
  • 5,955
  • 2
  • 29
  • 42
501
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
  • 57,282
  • 86
  • 216
  • 316
469
votes
19 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
  • 14,154
  • 15
  • 58
  • 97
464
votes
11 answers

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

I would like to use ::before to place SVG images before some selected elements: #mydiv::before { content: ''; display: block; width: 22px; height: 10px; margin: 10px 5px 0 10px; } Above code just displays the…
Sunny
  • 9,245
  • 10
  • 49
  • 79
414
votes
11 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
  • 7,326
  • 4
  • 29
  • 43
386
votes
9 answers

How can I make an SVG scale with its parent container?

I want to have an inline SVG element's contents scale when size is non-native. Of course I could have it as a separate file and scale it like that. index.html: foo.svg:
bjb568
  • 11,089
  • 11
  • 50
  • 71
385
votes
13 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
  • 5,391
  • 11
  • 34
  • 34
377
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,188
  • 4
  • 25
  • 36
1
2 3
99 100