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.

6
  • Possible duplicate of What is the default namespace for HTML / HTML5? Commented Dec 22, 2015 at 2:56
  • It's not a duplicate. That question is "What is the default namespace for HTML?" The answer was, "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. Commented Dec 22, 2015 at 4:04
  • 1
    Yes - in XHTML. See alohci.net/application/xhtml+xml/xhtml-demo.xhtml Commented Dec 22, 2015 at 17:59
  • 1
    Also see HTML 5, inline SVG, and namespace awareness for SVG DOM Commented Dec 22, 2015 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. Commented Dec 22, 2015 at 19:51

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

All the modern browsers support XML namespaces in XHTML. See alohci.net/application/xhtml+xml/xhtml-demo.xhtml for an example based on the OP's question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.