When to use the xmlns attribute in the html element?

Asked

Viewed 5,823 times

9

In HTML5, when to use xmlns? Thank you!

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="http://www.facebook.com/2008/fbml">
      ...
</html>

1 answer

12


In his example, xmlns="http://www.w3.org/1999/xhtml" indicates that the syntax used in the document is actually XHTML5 and not HTML5.

The following lines create several namespaces XML, used to define your own tags. Example: taking xmlns:h="http://java.sun.com/jsf/html" you could have tags in your document as follows:

<h:pessoa>
    <h:nome>NOME</h:nome>
    <h:idade>IDADE</h:idade>
</h:pessoa>

where the definition of tags <h:...> is given in http://java.sun.com/jsf/html.

In short:

If you are serving only documents purely in format HTML5, use the pattern:

<!DOCTYPE html>
<html>
    <!-- sua página -->
</html>

But if you want to serve documents with format XHTML5, then it is necessary to include the attribute xmlns in the html tag:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- sua página -->
</html>

The differences between HTLM5 and HTML4en may be useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.