...

View Full Version : no <link> tag in HTML 4 - does not validate



crmpicco
10-09-2007, 07:28 PM
<link rel="shortcut icon" href="/favicon.ico"></link>

Error: document type does not allow element "LINK" here

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


I tried to validate my HTML in the w3 validator just to see how much i needed to change and it gave this error. Does this mean that I can't use a <link> tag in HTML 4?

Picco

Bill Posters
10-09-2007, 07:31 PM
Show us your code so we can see where you've placed the link element.

crmpicco
10-09-2007, 07:41 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>AyrshireMinis.com - a Mini E-Community</TITLE>
<script language="JavaScript" type="text/javascript" src="/mini/js/general.js"></script>
<link rel="stylesheet" type="text/css" href="/mini/inc/style.css" />
<link rel="shortcut icon" href="/favicon.ico"></link>
</HEAD>
<BODY>


Merci!

rmedek
10-09-2007, 07:56 PM
You can use link…you just don't have to close it:


<link rel="stylesheet" type="text/css" href="/mini/inc/style.css">
<link rel="shortcut icon" href="/favicon.ico">

Note I got rid of the trailing slash in the first link…self-closing tags aren't used in HTML, only XHTML.

CFMaBiSmAd
10-09-2007, 07:59 PM
Edit: Basiclly says that same as above ^^

In HTML there are two problems with the posted code -

Your first <link tag is using a / to close the tag. This is not permitted in valid HTML and is actually what is causing the error you posted.

Your second <link tag is correct HTML, except that </link> is not a valid tag.

So, if you remove the / from the first one and the </link> from the second one, it will validate as HTML (tested.)

crmpicco
10-09-2007, 08:56 PM
excellent, many thanks to both of you!

Picco



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum