简体   繁体   中英

WP : Stray start tag HTML in validator?

I am trying to validate this HTML document in http://validator.w3.org/#validate_by_input but I am getting the following errors:

 Line 10, Column 71: Stray start tag html.
<html dir="rtl" lang="ar" prefix="og: http://ogp.me/ns#" class="no-js">

This is the HTML I am inputting:

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if IE 7]><html <?php language_attributes(); ?> class="ie ie7 no-js" /><![endif]-->
<!--[if IE 8]><html <?php language_attributes(); ?> class="ie ie8 no-js" /><![endif]-->
<!--[if !(IE 7) | !(IE 8)  ]><!--><html <?php language_attributes(); ?> class="no-js" /><!--<![endif]-->
<head>

The <meta> tag here implies an additional <html> and <head> tag before.

According to the HTML5 standard some tags are optional. <html> and <head> are such tags. You can drop them, but the parser will insert them, where needed. In your case they are needed before the <meta> tag, because <meta> is defined as a child element to the <head> tag, which in turn is a child of <html> .

So what the validator actually sees is this:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if IE 7]><html <?php language_attributes(); ?> class="ie ie7 no-js" /><![endif]-->
<!--[if IE 8]><html <?php language_attributes(); ?> class="ie ie8 no-js" /><![endif]-->
<!--[if !(IE 7) | !(IE 8)  ]><!--><html <?php language_attributes(); ?> class="no-js" /><!--<![endif]-->
<head>

Now it is obvious, why it complains about the "second" <html> tag.

The solution would be to just change the ordering of your tags. Put the <html> and <head> tag before the <meta> tag, and you should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM