Måns Nilsson
Måns Nilsson

Reputation: 451

HTML page won't validate

Can somebody explain why this HTML document won't validate as HTML5 (using http://validator.w3.org/)? I get three errors:

  1. Line 1, Column 33: Element head is missing a required instance of child element title.
  2. Line 2, Column 16: Stray start tag html.
  3. Line 2, Column 16: Cannot recover after last error. Any further errors will be ignored.
<!DOCTYPE html> //Random comment
<html lang="sv"> //Random comment
<head>
  <meta charset="utf-8" /> //Random comment
  <title>Startsida - Läxhjälpen</title> //Random comment
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <link href="laxhjalpen.css" rel="stylesheet" /> //Random comment
</head>
<body class="startpage"> //Random comment
  <header> //Random comment
  <div class="hwrap"> //Random comment
    <a href="./"><img class="logo" alt="Startsidan" src="./Images/laxlogo.png" /></a> //Random     comment
    <h1>Läxhjälpen</h1> //Random comment
  </div>
   <p class="tagline">Vi hjälper dig att förstå!</p> //Random comment
 </header>
  //Random comment
<section class="menu"> //Random comment
  <h2><a href="om-oss.html">Om oss <span style="color:blue;">&#x3020;</span></a></h2>
  <p>Man måste inte vara plugghäst för att kunna plugga. Vi själva är exempel på det.</p>
</section>
<section class="menu"> //Random comment
  <h2><a href="arbeten.html">Vad vi gör <span style="color:grey;">&#x2318;</span></a></h2>
  <p>Vi hjälper dig att plugga alla ämnen i skolan och förbereda dig för prov på bästa möjliga     sätt.</p>
</section>
<section class="menu"> //Random comment
  <h2><a href="blog.php">Blogg &#x272A;</a></h2>
  <p>Ta del av andra människors erfarenheter med vår tjänst.</p>
</section>
<section class="menu"> //Random comment
  <h2><a href="contact.php">Kontakt &#x260E;</a></h2>
  <p>Kontaktformulär, telefonnummer och adresser för att kontakta oss.</p>
</section>
  <footer>
    <small>&copy; Måns Nilsson AB</small> //Random comment
  </footer>
</body>
</html>

Upvotes: 1

Views: 444

Answers (2)

Diego Claudiu
Diego Claudiu

Reputation: 334

You should be using <!--Random comment--> INSTEAD of //Random Comment

HTML comments =

// This is usually used within PHP or JQuery to comment out A LINE

Upvotes: 0

Quentin
Quentin

Reputation: 943547

//Random comment is not a comment in HTML. It is text content. Since such content is only allowed in the body (and the title), this generates an html element containing a head element (without a title) and a body element.

(Note that while html, head and body elements are required, the start and end tags for those elements are optional. The start and end tags for the title element are mandatory which is why the text ends up in the body and not the title)

<!-- This is an HTML comment -->

Upvotes: 8

Related Questions