Question

I tried W3C Markup validation with a simple HTML page.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Title</title>
    <script src="script/myScript.js" type="text/javascript"></script>
    <link href="style/theme.css" rel="stylesheet"></link> 
     <!--[if lte IE 8]>
    <link href="style/themeIE8.css" rel="stylesheet"></link>
    <![endif]-->     
    <noscript>Please enable JavaScript in your browser to view this page properly, to view the basic page of the site click the link <a href="no-javascipt/main.aspx">main.aspx</a>
   </noscript>

</head>
<body class="layout">
   <div class="header"></div>
   <div class="content"></div>
   <div class="footer"></div>
</body>
</html>

and got the following errors

enter image description here

I guess in the noscript tag (or generally in the head tag itself) using DOM elements like a is not okay, Is there any alternative to that? i.e. if script is not found provide a link to a page that doesn't need script

and any idea as to why I am getting the errors for link & body tags? Thanks

Was it helpful?

Solution

link tag doesn't have a close tag, </link>. As such, it's invalid. If you want to close it inline, do it like this:

<link ... />

Also, you need to shift your <noscript> tag inside the body tag and between the head tag as it contains text content.

Reference

Sitepoint Reference


Though, using something like this is valid if you place in the head tag 1.

<noscript><link href="style/theme.css" rel="stylesheet" /></noscript>

1. In a head element, if scripting is disabled for the noscript element
   The noscript element must contain only link, style, and meta elements.

In a head element, if scripting is enabled for the noscript element
The noscript element must contain only text, except that invoking the HTML fragment parsing algorithm with the noscript element as the context element and the text contents as the input must result in a list of nodes that consists only of link, style, and meta elements that would be conforming if they were children of the noscript element, and no parse errors.

Correct Markup

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Title</title>
    <script src="script/myScript.js" type="text/javascript"></script>
    <link href="style/theme.css" rel="stylesheet" />
     <!--[if lte IE 8]>
    <link href="style/themeIE8.css" rel="stylesheet" />
    <![endif]-->     
</head>
<body class="layout">
<noscript>Please enable JavaScript in your browser to view this page properly, to view the basic page of the site click the link <a href="no-javascript/main.aspx">main.aspx</a>
   </noscript>
   <div class="header"></div>
   <div class="content"></div>
   <div class="footer"></div>
</body>
</html>

OTHER TIPS

Check you style link which is not right. Style link should be self close. i.e.

<link href=".."  rel="stylesheet" />

and because there is written text not linked style or script so it should be under body tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top