Shlomif's Technical Posts Community - Tech Tip: Empty tag in XHTML served as text/html [entries|archive|friends|userinfo]
Shlomif's Technical Posts Community

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| Shlomi Fish's Homepage Main Journal Homesite Blog Planet Linux-IL Amir Aharoni in Unicode open dot dot dot ]

Tech Tip: Empty tag in XHTML served as text/html [Jan. 14th, 2014|04:25 pm]
Previous Entry Add to Memories Share Next Entry

shlomif_tech

[shlomif]
[Tags|, , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |Set Fire to the Rain - Cover by Spencer Borup with Cimorelli]

If you serve XHTML (= HTML written using XML grammar and conventions) as Content-Type: text/html, you may be tempted to write an empty <div> tag as a standalone XML tag with a trailing slash using <div id="my_anchor" />. Don’t do that, because with text/html (a.k.a “tag-soup”) the browser may think you just have an opening tag and will look for a closing tag elsewhere. Instead, write a pair of opening and closing tags, e.g: <div id="my_anchor"></div>.

Using the first form confused both Firefox (24.2.x in my case) and Google Chromium (whatever shipped with Mageia at the time), and made them misrender my page, despite the fact that it validated as valid XHTML. Perhaps I should have considered putting the id=".." inside a meaningful sub-section of the document, but I implemented something for skipping a section navigation menu.

LinkReply