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

・1 min read

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 attention when it was new, but now that React is so standard and so widely adopted in bootcamps I'm worried that some of the gotchas are getting overlooked.

Thoughts?

DISCUSS (16)
 

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.

 

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.

 

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:

 

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.

 

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

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

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

 

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 😊

 

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!

 

No. I don't even know the difference between the two terms beyond "XHTML have a X"

 

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.

 

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.

 

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

 

I randomly try


,
,
until one works.

Let's see who will figure it out.

Classic DEV Post from Nov 19 '18

What’s a concept you understand now, but took you forever to grasp?

I’m sure we all have plenty of answers to this one, but sometimes we forget how...

A Canadian software developer who thinks he’s funny.