Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid HTML1500 Tag cannot be self-closing warning in IE when using embedded svg?

Using what I believe to be pretty standard embedded svg:

<!DOCTYPE html> <html> <body style="padding:50px">    <svg width="100" height="100">     <circle cx="50" cy="50" r="20" />   </svg>  </body> </html> 

IE (11) gives me a warning "HTML1500: Tag cannot be self-closing. Use an explicit closing tag." (DevTools, Console tab).

It's true that if I change the <circle.. to:

<circle cx="50" cy="50" r="20"></circle> 

the warning goes away, but that looks strange to me..

The IE devtools have occasionally found real unclosed-tag errors, so it would be sad to see it render un-useful from this kind of noise..

Is there any way of making IE happy without resorting to adding closing tags everywhere?

Update: Note that the question is about "Foreign elements", not "Void elements" (http://www.w3.org/html/wg/drafts/html/master/single-page.html#elements-2). <svg> is not self-closing (it's defined as belonging to the Container element category: http://www.w3.org/TR/SVG/struct.html#SVGElement).

<circle.. is defined as a Basic shape element (http://www.w3.org/TR/SVG/shapes.html#CircleElement), which means that it is self-closing. In reading 8.1.2 of the html5 spec:

Foreign elements whose start tag is marked as self-closing can't have any contents (since, again, as there's no end tag, no content can be put between the start tag and the end tag). Foreign elements whose start tag is not marked as self-closing can have text, character references, CDATA sections, other elements, and comments, but the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand.

it seems (to me) like it is saying that tags inside an <svg> element (i.e. foreign elements) are self-closing if the svg-spec says they are, and when defining start tags (8.1.2.1), #6 says that the / in <tagname ... /> is optional on e.g. <br/>, but not on <circle ../>:

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

So I believe the document is conforming as-is. I'm unsure if the using a closing </circle> tag would be conforming.

like image 348
thebjorn Avatar asked Mar 09 '15 17:03

thebjorn


People also ask

Is SVG a self closing tag?

No. It does not have an end tag. Example. <circle cx="50" cy="50" r="40" /> All SVG elements dont have an end tag.

Is embedded tag is a self closing tag?

The HTML <embed> tag is used for embedding an external application or interactive content into an HTML document. Note that the <embed> element is an empty element (no closing tag is used).

Does HTML5 have self closing tags?

All tags in XML or XHTML can be used as self-closing by closing them with (<.. />). HTML5: Using a slash is absolutely optional. HTML4: Using a slash is technically invalid. However, the W3C's HTML validator still accepts it.

What is optional closing tag?

Optional HTML Closing Tags Some closing tags are optional, however. The tags are optional because it's implied that a new tag would not be able to be started without closing it.


1 Answers

See this question: Are (non-void) self-closing tags valid in HTML5?

Basically, HTML5 doesn't really do self-closing tags. Instead it has void tags, like <br>. This also explains why <script> isn't self closing when you are using an external js file; <script> isn't a void element. The SVG you are writing is actually html, so it has to follow HTML5's rules, not XML's.

I think you should just add a closing tag so that you can get the benefits of more important warning/errors in the console. Alternatively if your page was XHTML, I believe you could use a self closing circle tag.

like image 187
Tom B. Avatar answered Sep 22 '22 13:09

Tom B.