[whatwg] Allow Select SVG Elements In <head>

Hugh Guiney hugh.guiney at gmail.com
Fri Aug 27 03:20:15 PDT 2010


I'm authoring an XHTML host document with namespaced inline SVG and
XLink. I have vector images that recur throughout the site. I'd like
to implement SVG's <defs> and <use> to reduce the file size of the
document and keep style separate from content, as with CSS.

If I put an SVG tree with <defs> anywhere in the XHTML document, other
trees with <use xlink:href> will correctly reference it, as tested in
the latest public release Gecko, Webkit, and Opera. So the question
becomes, where do I put it? The most obvious answer seems to be
<head>, since, like CSS definitions, this is metadata being defined
for use elsewhere in the document. The only problem is, Validator.nu
doesn't like it:

"Error: SVG element svg not allowed as child of XHTML element head in
this context. (Suppressing further errors from this subtree.)"

Same error when ditching the root <svg> and including only <defs>, the
result of which still works in all but Opera.

This error can be avoided if the <defs> tree is put in the XHTML
<body>, but then there is blank space the size of the defined shapes
at the top of the document in all 3 engines. A workaround is to give
<svg> a @width and @height both of 0. But leaving the definitions in
the <body> when they technically don't represent contextual content
strikes me as non-semantic.

My proposition would be to simply spec a subset of SVG consisting only
of metadata elements as valid in HTML's <head> context. This could be
just <defs>—I'm unsure if there are any other elements that fit this
definition since I am relatively new to SVG; but in either case it'd
aid semantics and is already supported in today's SVG-capable
browsers.



More information about the whatwg mailing list