When to use the xmlns attribute in the html element?

6

In HTML5, when to use the xmlns attribute? 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>
    
asked by anonymous 22.03.2016 / 03:43

1 answer

8

In your 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: Having 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 <h:...> tags is given in http://java.sun.com/jsf/html .

In short:

If you're only serving documention purely in HTML5 format, use the default:

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

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

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

Differences between HTLM5 and HTML4 en can be useful.

    
24.03.2016 / 04:57