1

I've been using the validator.w3.org service for my XHTML Transitional webpages and have been very happy with it - it shows me incorrect syntax and unclosed tags easily.

However, we're coding our new site in HTML5 - so the Doctype naturally becomes . The w3 validator therefore validates the page as HTML5. I've used this for some time but only just realised that it does not notify me of un-closed tags. For example, if I use

<div><p>This is my text and I am not closing this P tag</div>

then a XHTML validator will notify me of the above problem, but validation on HTML5 does not show me that the above is a problem. Is there any way I can resolve this?

Additionally, I've freely been using code like the following, which shows the following error if validated as XHTML, but does not have any problems if validated as HTML(5) :

 Line 266, Column 51: document type does not allow element "h5" here; missing one of  "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

<a href="/outlet/" title="" rel='nofollow'><h5>OUTLET</h5></a>

I thought the above (to use an H5 inside an A element) is OK on HTML5, but after realising that HTML is not validated as XHTML, I'm quite confused! If I want to build a web page to "good standards" - what standard do I follow? I definitely want to make use of HTML5, but I want to also ensure that my code has the correct closing tags (as in the above P tag example) and also follows any other "good standards". Please advise what you would do?

Many thanks

rishijd
  • 1,294
  • 4
  • 15
  • 32
  • Try http://html5.validator.nu/ ? – Edu Apr 17 '12 at 09:28
  • I checked that, but it too is similar to validator.w3.org such that it does not show the errors like the above, unless I force validation as XHTML. Forcing validation on XHTML on either site however also throws errors for NAV, HEADER, FOOTER etc. HTML5 elements as well. The only solution at the moment seems to be this however, where I need to fork out which errors concern me and which don't (i.e. HTML5 unrecognised elements are the ones I should ignore if I validate it as XHTML) :( – rishijd Apr 17 '12 at 09:36

2 Answers2

0

When validating in xhtml mode, everything has to match that specification. On the other hand, html5 specification allows a lot of freedom. For this specific case, the html5 specification on markup syntax says:

"A non-void element must have an end tag, unless the subsection for that element in the HTML elements section of this reference indicates that its end tag can be omitted."

The specification of paragraph element says that it is ok to omit the end tag, if it is immediately followed by div tag, as it is in your example.

"A p element’s end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, dir, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hr, menu, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is not an a element."

I think you have to write valid xhtml if you want that kind of consistency. Could you use some editor that would check the end tags for you?

Edu
  • 2,017
  • 17
  • 23
  • Thanks for your reply. I use notepad++ currently - just for my info, is there anything I can do with this editor (or any other free ones) we can try to check things like end tags? – rishijd Apr 18 '12 at 12:38
0

If you want to validate a page at a URL as XHTML with the W3C HTML validator, and the page has <!DOCTYPE html> as its doctype, then you must serve the page with an XML mime type such as application/xhtml+xml to the validator.

This is a good thing. Only if you use such a mime type will browsers treat your XHTML as XHTML, otherwise they will treat it as HTML and all your careful XHTML will be be so much tag soup. With HTML5, validators now behave the same way as browsers.

Otherwise, you should learn what is "correct closing tags" in HTML. Which means such things as closing </p> tags may be omitted in many circumstances.

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • Thanks very much. "application/xhtml+xml" - I checked more about this on http://html5doctor.com/html-5-xml-xhtml-5/ and http://stackoverflow.com/questions/1076897/html5-syntax-html-vs-xhtml - I don't understand the part about this not working on IE - e.g. "so no rendering in Internet Explorer for the moment)" - we definitely need our site working on IE7+, plus some functionality on IE6. In that case, is application/xhtml+xml an option for me? – rishijd Apr 18 '12 at 12:39
  • @rishijd - If you need to support IE prior to version 9, then you can't serve files as `application/xhtml+xml` to them. One option is to use content negotiation. This means that you serve the file with either `application/xhtml+xml` or `text/html` depending on information on the HTTP request header such as the "acceot" header. If the "accept" header contains the string "application/xhtml+xml" then send the file with the `application/xhtml+xml` content type and `text/html` otherwise. – Alohci Apr 18 '12 at 21:05