Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Find Silent Mistakes in Your HTML

In this lesson, you checked Rosa’s draft of a Visit the Garden page, which looked almost right and put nothing in the Console. You found its silent mistakes in three steps: the validator, the Elements panel next to the file, and the Accessibility pane.

Key Points

  • HTML never reports a mistake. The browser repairs what it can and shows the page anyway, and the Console stays empty, so you check a page yourself.
  • Step one, the validator. The W3C’s validator, the Nu Html Checker at https://validator.w3.org/nu/, checks your file against HTML’s rules. Your live preview’s address works only on your own computer, so choose text input in its Check by menu, paste the whole file into the box, and click Check.
  • Read the first errors together. For Rosa’s draft, one missing </a> gave four errors. The first two point at line 10: “End tag p seen, but there were open elements.” and “Unclosed element a.” Together they say the paragraph ended while the link was still open. The last two, at </main> and </body>, are the same open link, still open further down. So you add the link’s end tag, </a> after “plot map”, and leave alone the </p> that the first error highlights.
  • Step two, the Elements panel next to your file. The validator says what’s wrong in the file, and the Elements panel shows what the browser did about it. As with Rosa’s unclosed <em> in her watering rota, the parser closed the <a> at the end of the paragraph and then opened a new one before the next paragraph, so that paragraph’s </p> couldn’t close it.
  • That second <a>, which isn’t in the file, stayed open to the end of <main> and wrapped the opening times and the photo, so both led to the plot map, and a third, empty <a> followed </main>. The validator’s one open link became three links in the tree.
  • Watch out: a missing end tag doesn’t stay on its own line. When a link or italics leak further down a page, look for the first unclosed element above them.
  • With </a> added, the tree matched the file, with one <a> inside the first paragraph, and the validator showed no errors or warnings. Warnings flag markup that’s allowed but worth a second look, and Rosa’s page had none.
  • Step three, the Accessibility pane. The validator checks the rules for writing HTML, not what an element means to a visitor. When you selected the <img> and opened the Accessibility tab, beside Styles, the pane showed its role, image, and its name, photo. That’s what a screen reader announces. That’s valid HTML, and it tells a visitor nothing.
  • With alt text that says what the photo shows, “Plot 7 in August, full of staked tomatoes”, the name changes to match. The validator passes both versions, so only your own reading, with the pane’s help, can tell which one helps.

Final Code

Rosa’s page, with the link closed and the photo’s alt text rewritten:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In the last lesson, the plots page got a table. Your pages now hold a lot of markup, and HTML never tells you when some of it is wrong. In this video, you’ll learn three checks that find those silent mistakes.

00:14 Rosa has drafted a Visit the Garden page and wants you to check it. Open it in Chrome. The opening times are blue and underlined, like a link. Click the photo, and it opens the plot map too.

00:25 Rosa only linked the words plot map.

00:29 Yet the Console is empty. No error or warning tells you where to start.

00:36 Start with the W3C’s HTML validator, the Nu Html Checker, at validator.w3.org/nu. It reads your file and checks it against HTML’s rules. Your live preview’s address works only on your own computer, so the validator can’t fetch it.

00:53 Instead, in its Check by menu, choose text input. Paste all of Rosa’s file into the box, and click Check. It lists four errors, each with its place in the file.

01:07 Read the first two together: both point at line 10. A paragraph ended while something was still open, and the link was never closed. So the open thing is the link.

01:19 The last two, at the end of the main and body elements, are the same open link, still open further down. One missing end tag caused all four. So add the link’s end tag and leave the paragraph’s alone.

01:32 First, see what the browser made of it.

01:37 The validator says what’s wrong in the file. The Elements panel shows what the browser did about it. Remember Rosa’s watering rota? Her emphasis was never closed.

01:46 The parser closed it at the end of the paragraph, then opened a new one around the next paragraph.

01:53 The parser does the same with a link. Open the Elements panel on the visit page, and expand the main element. The first link holds plot map, as in the file.

02:03 Then comes a second link that isn’t in your file. Like the emphasis, it opens before the next paragraph, so that paragraph’s end tag can’t close it. It stays open to the end of the main element, and wraps the opening times and the photo.

02:18 That’s why both lead to the plot map. After the main element, there’s a third, empty one. The validator’s one open link became three links in the tree. So watch out: one missing end tag doesn’t stay on its own line.

02:33 When a link or italics leak further down, look for the first unclosed element above them.

02:40 Now add the link’s closing tag after plot map, and save. The tree now matches the file, with one link, inside the first paragraph. Check again, and the validator shows no errors or warnings.

02:53 Warnings flag markup that’s allowed but worth a second look, and there are none here.

02:59 A clean result doesn’t make the page right. The validator checks the rules for writing HTML. It can’t tell what an element means to a visitor. For the last check, select the image in the Elements panel, and click the Accessibility tab, beside Styles.

03:15 Its role is image, and its name is photo. That’s what a screen reader announces. It’s valid HTML, and it tells a visitor nothing.

03:25 Give it alt text that says what the photo shows, Plot 7 in August, full of staked tomatoes. Save, and the name changes to match. The validator passes both versions.

03:36 Only your own reading, with the pane’s help, can tell which one helps a visitor.

03:43 HTML won’t report its mistakes, so check every page three ways. The validator checks the file against HTML’s rules. The Elements panel, next to your file, shows what the browser repaired.

03:55 The Accessibility pane shows what each element means. Next, in Exercise: Repair the Tool Shed Page, you’ll put the three checks to work on Rosa’s tool shed page.

Become a Member to join the conversation.