7. HTML syntax inconsistencies?


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
So I’m made somewhat confused by how html seems to work. Before this lesson the teacher wants us to always close our tags like

or however you want to put it but it has to have a closing tag.

But when in this lesson we start adding more headings it doesn’t ask for the closing tag, so me being a cheeky ■■■■■■ thought that it was a mistake or was purposely leaving it out or something to put the closing tag for the additional headings…and that when I clicked save and continue or whatever it would throw an error or something. Not only does it not throw an error, the code seems to work fine.

Which furthermore confuses me. Why put h1 around the entire webpage’s content, and then within use other headings to override that - which is what the teacher has instructed it seems? Is there a purpose to that? Or does putting other h1, 2,3,4 etc in an h1 just change the font size to the average between h1 and whatever h# you’re referring to? Or is it a straight override? This had me confused. Anyway, here’s my code!

		Headings & Paragraphs

<do not remove the three backticks above>

Some tags are self-closing, <h1> is not one of those.

Before closing a tag, you must make sure that all tags inside it are closed first, it’s like matching parentheses, I think you’ll agree this isn’t how parentheses are used:


That should instead be:


Browsers are also sometimes too lenient, interpreting things to their best ability even when something could be interpreted multiple different ways. It’s a good idea to use a linter/style checker when interpreters are a bit too lenient and won’t complain about your mistakes

Or uh, I suppose <h1> might even be optionally self-closing, I can’t say either way, that might or might not be something browsers just let slip

Got a more definitive answer now.
Says the end tags may not be omitted.

There’s a command-line tool named tidy that cleans up html and displays warnings and errors, for your code it outputs the following warnings:

line 12 column 17 - Warning: missing </h1> before <p>
line 15 column 13 - Warning: missing </h3> before <p>
line 17 column 21 - Warning: missing </h5> before <p>
line 19 column 17 - Warning: discarding unexpected </h1>
line 12 column 17 - Warning: trimming empty <h1>
line 15 column 13 - Warning: trimming empty <h3>
line 17 column 21 - Warning: trimming empty <h5>
line 18 column 21 - Warning: trimming empty <p>

And cleans it up to:

<!DOCTYPE html>
  <meta name="generator" content=
  "HTML Tidy for HTML5 for Linux version 5.2.0">
  <title>Headings & Paragraphs</title>

That’s not how firefox interprets your code, but it’s undefined how it should be so…

It also links to an online validator:

1 Like

It’s strange because while you say that the end tags may not be omitted either codeacademy or Microsoft edge allows this because my code as I posted worked just fine. Idk tho

1 Like

Yes. Browsers prefer to guess rather than display an error. If your code is correct then there’s less guessing and less oddities as a result.

1 Like

Okay thanks! Just needed that cleared up.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.