-1

I have strange bug with !DOCTYPE html.

When I'm trying to use HTML5 Doctype, then my page looks weird. All scripts looks like not closed properly.

But when I'm changing to !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", then everything looks good.

I don't understand what's wrong with page structure and why it's happened only with HTML5.

unor
  • 92,415
  • 26
  • 211
  • 360
Donnie
  • 373
  • 2
  • 7
  • 28

2 Answers2

2

HTML5 completely removed and reworked many HTML4 elements (which XHTML 1.0 is based on). If a website is coded primarily in XHTML 1.0, you can't just switch over to HTML5 and assume things won't break.

Your best option is to run your converted-doctype code through W3C's HTML validator at https://validator.w3.org and have a look through the errors and warnings which it generates. This should give you an idea of why things aren't working the way you want them to be.

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • It's even worse: it's XHTML :) – Álvaro González Apr 18 '16 at 15:45
  • I think he describes the opposite. – Stelium Apr 18 '16 at 15:46
  • 1
    HTML5 was designed to be backwards compatible with legacy sites - although the semantics of a number of HTML 4 elements have changed, implementations don't suddenly behave differently just by switching from one strict doctype to another. – BoltClock Apr 18 '16 at 15:47
  • @BoltClock this is true, but I think in OP's case going from XHTML 1.0 to HTML5 may be too much of a large step. – James Donnelly Apr 18 '16 at 15:51
  • 1
    It's strange though. The main browsers don't really distinguish between doctypes; if the file type is HTML, the HTML parser is used. There are no separate HTML4 and HTML5 parsers! So it's technically not possible to make your site look different by switching doctypes (except when you use a doctype that triggers quirks mode). – Mr Lister Apr 18 '16 at 19:38
0

Thank you guys, for your help!

I found how I can solve it. In my case, error was in one extension, which used $dom->saveXML() method in observer. And before rendering this method parsed DOM and removed/replaced HTML output.

Donnie
  • 373
  • 2
  • 7
  • 28