Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a HTML page need to be wellformed?

Tags:

html

css

I'm developing a website with friends. I'm coding the server program and my HTML/CSS knowledge is low.

I received from the guy whose job is the HTML/CSS stuff a page which had a section which looked like this:

<div>
    <form>
</div>
    </form>

This is as far as I know (I noticed when I tried to inherit it) not well formed.

after googling around I just figured out that non well formed HTML won't even show up.

So I asked him about the <div> thing and he just said rude "The page looks as we want it to look, doesn't it?!"

And he is right, it does.

But now I'm asking my self (I'm a bit cowardly as I know as a Highlevel language coder as I'm, disrespect a standard leads into undefined behaving) will the look of, what he calls "It does what we want" be interpreted by each browser the same? Or even I'm wrong and this is allowed because of some css stuff?

Or is he just that kind of coder who tries around, and it is luck, that it looks like we want, he doesn't even know why it does so?

And maybe some browsers we don't know won't even show up the page?

Sorry for my bad question style, but I don't really know how to ask the question, as I'm not really in HTML/CSS.

like image 789
dhein Avatar asked Dec 25 '22 15:12

dhein


2 Answers

Short answer: Yes.

Long answer. Some browsers are forgiving of badly formed html ... but sometimes in different ways. Some issues you may come up against:

  • CSS styling acts differently across browsers
  • You may trigger Quirks mode
  • Manipulating items with JavaScript may give unexpected results...etc

Good luck.

like image 52
Ruskin Avatar answered Jan 21 '23 06:01

Ruskin


Your friend (who you should stop calling a coder, he isn't) is wrong.

On a practical, down-to-Earth, level, in this specific case, the browsers end the form when they see the </div> end tag. So if you have

<div>
    <form>
</div>
   <input name="what">
    </form>

the input will not be submitted with the form.

And this is one case where the latest browsers all agree on how to act, but in general, different browsers respond differently to errors. (I have compiled some examples of that on my own website, here.)

So your friend may be satisfied with the site working in one particular browser, but he'll be out of luck when the browser updates to a new version. Not to mention other browsers.

As a high level coder, would you deliver an application that compiles, but with warnings?

PS: you said "I just figured out that non well formed HTML won't even show up." but that is a misunderstanding. Most browsers throw an error when they encounter non-well-formed XHTML, but in the case of HTML, they show as much as they can and work very hard on recovering from errors. Still, different browsers use different error-recovery algorithms, so you really really shouldn't count on that.

like image 43
Mr Lister Avatar answered Jan 21 '23 05:01

Mr Lister