Hacker News new | ask | show | jobs
by seasoup 5970 days ago
If you don't close your tags,

<div>foo<a>bar<span>baz box

how can you tell the difference between,

<div>foo<a>bar</a><span>baz</span> box</div>

and

<div>foo<a>bar<span>baz</span> box</a></div>

3 comments

By "don't close your tags", I mean "don't close your tags when the HTML spec does not require you to." You still need to close your <a>, <div>, and <span> tags. You don't need to close your <li>, <th>, <tr>, <td>, <dl>, <dt>, and several other tags. You don't even need to open your <html> and <head> tags, if you're not doing funky stuff like putting comments in them.
The HTML tag closing rules specify they only get closed when they have to be. So neither of your solutions is correct. It is:

<div>foo<a>bar<span>baz box</span></a></div>

my solution was to merely demonstrate the difference between what a programmer writes and what gets sent as an http response.
Rendered html that will be sent has an http response should have ending tags. That doesn't mean the programmer/designer has to write them: #a dumb ruby example: def p(content) "<p>"+content+"</p>" end

p "hello" #=> "<p>hello</p>"