DEV Community

Do you think the differences between HTML and XHTML are generally well-understood?

Ben Halpern on May 01, 2018

React really threw a wrench in webdev by making XHTML cool. I think the subtle differences to look out for between HTML and XHTML got lots of atten...
Collapse
 
moopet profile image
Ben Sinclair

I didn't know anyone still used XHTML to be honest. I thought it was a grand experiment that was killed off by people not caring about how it was used and writing pages which broke in Internet Explorer, because Internet Explorer was actually doing The Right Thing.

Mind you, I don't do much front end stuff these days, and React is something that's always on my "to learn someday" pile.

Collapse
 
ben profile image
Ben Halpern

React's JSX is XHTML-like. It's neither HTML or XHTML or JavaScript. It's its own thing, but I think people can get tripped up when their React linter tells them that <div></div> should be <div /> but then they don't fully understand that self-closing tags are not a thing in HTML otherwise. And it's a mistake that won't throw an error but could cause a big mess down the line.

Collapse
 
asaaki profile image
Christoph Grabo

I wish self-closing tags were a thing in HTML(5), because <div></div> and friends are sometimes unnecessarily noisier than <div />. Probably the only feature of XML I like anyway.
I still write a lot of my <meta />s that way, even if not needed, but I run it through tidy, so it makes the HTML the way browsers mostly expect it to be. :shrug:

Collapse
 
ghost profile image
Ghost • Edited

Honestly, I've been working with HTML for ages and it wasn't until I started learning how to use APIs late last week that I realised there are some actual differences between HTML and XHTML.

Right now, my understanding is it's just a 'dialect' of HTML that's strict in formatting and that it's sometimes used in APIs? Does React actually require XHTML, though?

Edit: Woops! I got XML and XHTML confused :) Hah, maybe that's the issue!

Collapse
 
ben profile image
Ben Halpern

Hmmmm JSX is typically described as more or less aligned with XHTML, but yes it's its own beast. Perhaps I'm leaning too much on the early suggestions from the React folks to think XHTML, and maybe it's not as much of a talking point these days.

As an aside, do you type <br> or <br/> if you use that element in HTML? Just curious.

Collapse
 
coolgoose profile image
Alexandru Bucur

I typed
for a long time, I still refuse to not type selected="selected" old habits die hard I guess.

Thread Thread
 
ben profile image
Ben Halpern

This is a classic markdown-attempt-to-write <br/> 😄

Thread Thread
 
coolgoose profile image
Alexandru Bucur

I should give one beer for each markdown error :))

Collapse
 
andre profile image
André König

JSX is more inspired by an obsolete standard called E4X which in fact uses JS for processing XML. So in that sense it is indeed XHTML, but just because of the fact of processing XML. I don‘t think that the React team focused on XHTML because they thought it should be pushed, but this is just my opinion 😊

Collapse
 
mbtts profile image
mbtts • Edited

XHTML must be a well formed XML document. In other words every XHTML document is XML, but not every XML document is XHTML.

In simpler terms - "well formed" means all the tags need to close (or self close) and all attributes need to be in double quotes.

The other difference is that for an XHTML document to be valid it must to conform to the XHTML schema.

This was important when it was thought XML was so important it would eventually take over the world and so naturally it followed that the solution to every problem had to be more XML.

Fortunately the world saw sense before this ever became a reality.

Collapse
 
fleshwounded profile image
Fleshwound⚡

Whats XHTML? I dont even know what XML is lol... Seriously its not going to be fun if I had to guess

Collapse
 
cathodion profile image
Dustin King • Edited

I know I don't fully understand the difference. But they're the same in the sense that your code might not work in your target devices and then you tweak it until it does work.