0

It seems like it's possible to use namespaces in an HTML document. Although, I've never seen it done. If I used namespaces in my document would browsers render it correctly?

Here is your HTML:

<html>
<head>
</head>
<body>
   <input type="button"/>
</body>
</html>

Here is your HTML on namespaces:

<h:html xmlns:h="http://www.w3.org/1999/xhtml">
<h:head>
</h:head>
<h:body>
   <h:input type="button"/>
   <svg:svg xmlns="http://www.w3.org/2000/svg"/>
</h:body>
</h:html>

Any questions?

FYI SVG uses namespaces and is rendered correctly by browsers. See this.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • Possible duplicate of [What is the default namespace for HTML / HTML5?](http://stackoverflow.com/questions/34407468/what-is-the-default-namespace-for-html-html5) – Rob Dec 22 '15 at 02:56
  • It's not a duplicate. That question is "What is the default namespace for HTML?" The answer was, "http://www.w3.org/1999/xhtml". That was answered. This question is, "Will the browser render my page if I use namespaces in my HTML markup?" See the code above. – 1.21 gigawatts Dec 22 '15 at 04:04
  • 1
    Yes - in XHTML. See http://alohci.net/application/xhtml+xml/xhtml-demo.xhtml – Alohci Dec 22 '15 at 17:59
  • 1
    Also see [HTML 5, inline SVG, and namespace awareness for SVG DOM](http://stackoverflow.com/questions/23319537/html-5-inline-svg-and-namespace-awareness-for-svg-dom/23322429#23322429) – Alohci Dec 22 '15 at 18:04
  • I voted to close because "Any questions?" is not a question. Although it pains me to have to do that, because I love XHTML so much. Look at @Alohci's example: no doctype declaration, but still rendering in standards mode. So beautiful. – Mr Lister Dec 22 '15 at 19:51
  • @MrLister no it was written like a terrible commercial in the 80s https://www.youtube.com/watch?v=3FtNm9CgA6U, like why would you ever do this. i was acknowledging that it seems like a terrible idea to want to use namespaces. – 1.21 gigawatts Dec 22 '15 at 23:57

1 Answers1

1

Using XML mechanisms (like XML namespaces and prefixes and assuming that clients correctly process markup according to the XML processing model) is not a robust way to publish HTML. When publishing HTML, make sure you're doing it with what XML would call the "default namespace". You might get lucky that some browsers implement namespaces, or simply ignore prefixes, but I would recommend to not count on that. That's all different when you're just working in your own XML-based environment, where the two XML you're showing indeed are pretty much equivalent. But even then you should make sure that whatever leaves that environment matches the outside world's assumptions, such as HTML not using namespace prefixes at all.

dret
  • 531
  • 3
  • 7
  • 2
    All the modern browsers support XML namespaces in XHTML. See http://alohci.net/application/xhtml+xml/xhtml-demo.xhtml for an example based on the OP's question. – Alohci Dec 22 '15 at 17:57