tags:

views:

468

answers:

5

Hi,

I'm using Chrome version 5.0.375.55 and Firefox version 3.5.9 but I can't get the HTML5 code below to display a box.

<!DOCTYPE html> <!-- this tells browser, this is HTML5 -->
<html>
<body>
 <svg width="200" height="200"> 
 <rect
  x="0" y="0"
  width="100" height="100"
  fill="blue" stroke="red"
  stroke-width="5px"
  rx="8" ry="8"
  id="myRect" class="chart" />
 </svg>
</body>
</html>

The following sites stated that my browsers support HTML5 and svg so what gives?

http://caniuse.com/
http://www.html5test.com/
+1  A: 

Have you tried using the SVG XML namespace for your tags? Like so:

<html xmlns:svg="http://www.w3.org/2000/svg"&gt;
    <!-- ... -->
    <svg:svg width="200" height="200"> 
        <svg:rect
          x="0" y="0"
          width="100" height="100"
          fill="blue" stroke="red"
          stroke-width="5px"
          rx="8" ry="8"
          id="myRect" class="chart" />
    </svg:svg>
</html>
amphetamachine
+1 Thanks for your reply amphetamachine. I tried your solution but nothing displayed
01010011
I tried changing the file's extension to .xml and .xhtml as suggested in the following link and it still did not display the box: http://stackoverflow.com/questions/2304488/why-doesnt-svg-work-on-local-html-files
01010011
A: 

try in Firefox about:config, search for html and enable "true" value. What next? Wait will Firefox 4. As for WebKit please read: http://trac.webkit.org/wiki/WebKit%20plus%20SVG. You are not alone. I'm also waiting for SVG.

Vladislav
+4  A: 

This is how I got it to work I called the file test.xhtml

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"> 
 <rect
  x="0" y="0"
  width="100" height="100"
  fill="blue" stroke="red"
  stroke-width="5px"
  rx="8" ry="8"
  id="myRect" class="chart" />
 </svg>
</body>
</html>

Good luck!

Drew LeSueur
+1 It worked. Thanks a lot
01010011
+1  A: 

Firefox 4 will support SVG in HTML. WebKit will probably start working on it in the coming months.

Ms2ger
+1 Thank you ms2ger
01010011
+1  A: 

it worked by saving the file as xhtml, but does anyone know why?

At a guess, Chrome will only recognise SVG that is declared in the SVG namespace, and in turn namespaces are only used when parsing as XML. The HTML parser may not be namespace aware and so it won't treat the <svg> tag as something it recognises, even if you add a xmlns attribute.
Nick