Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    255
    Thanks
    113
    Thanked 0 Times in 0 Posts

    HTML Tag Namespace Attribute?

    When coding in XHTML, I notice that some websites add an XML namespace attribute to their HTML tag while some sites don't. What are the pros and cons of adding the namespace?

    Also, I've seen sites add direction and lang attributes as well. What are their pros and cons?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,729
    Thanks
    6
    Thanked 1,017 Times in 990 Posts
    You have to add a namespace to your document if you write XHTML because technically you are writing XML and tell the browser that you use the XHTML syntax for everything within the html element. The same would apply if you suddenly write SVG syntax in your document: You’d have to add an SVG namespace attribute to the SVG parent element so the parser knows that this is SVG. Otherwise it would technically lead to an error because it’s invalid XHTML.

    However, since most XHTML documents are still served as tag soup (text/html) the browsers don’t care that much which is why some people leave it (although it’s theoretically wrong).

  • #3
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by VIPStephan View Post
    However, since most XHTML documents are still served as tag soup (text/html) the browsers don’t care that much which is why some people leave it (although it’s theoretically wrong).
    Saying we don't care that much is untrue: we don't care at all. We parse XHTML served as text/html as HTML, so the fact the document claims to be XHTML in the DOCTYPE means nothing. Omitting the namespace declaration would break if it moved to actually being XHTML (likewise, a fair chunk of CSS and DOM stuff, as well as a small amount of other ECMAScript APIs).

    Generally, as long as you are working with text/html, you gain nothing by claiming to use XHTML, and you're better off using HTML.

  • #4
    Regular Coder jamesicus's Avatar
    Join Date
    Oct 2008
    Posts
    106
    Thanks
    0
    Thanked 11 Times in 10 Posts
    I illustrate multi-namespace use (view page source) on my XHTML+RDFa demonstation page (in my signature block) when the document is served as content-type application/xhtml+xml to XML compliant Browsers.

    James
    Last edited by jamesicus; 06-07-2009 at 03:17 AM. Reason: forgot information
    Web Developer Tool Kit - for creating Standards compliant and Interoperable web pages
    W3C Markup Validation Service - validate HTML code for reliable rendering in all Browsers
    WAVE accessibility evaluation tool - check page structure, image alt text, form labels, etc.

  • #5
    Regular Coder
    Join Date
    Oct 2008
    Posts
    255
    Thanks
    113
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gsnedders View Post
    Generally, as long as you are working with text/html, you gain nothing by claiming to use XHTML, and you're better off using HTML.
    Why do you say that?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •