Hey guys, im making a website with strihttp://www.daniweb.com/forums/newthread.php?do=newthread&f=143ct xhtml design and everytime i upload an image, it just wont validate when i try the w3schools validator.
It keeps giving me an error message: "
1. Error Line 14, Column 36: document type does not allow element "img" here

<img src="banner.jpg" alt="banner"/>

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)."

Even though i think the syntax is right:S
Maybe im tired thats y i cant spot it, but it would be great if someone could let me know whats wrong with it:s
The source code is:

1. <?xml version="1.0" encoding="UTF-8"?>
2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4.
5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6.
7. <head>
8. <title>Hello</title>
9. </head>
10. <body>
11. </body>
12.
13.
14. <img src="banner.jpg" alt="banner" />
15.
16. </html>

Recommended Answers

All 6 Replies

the image has to be inside the <body></body> tags, </body> represents the end of displayable space

I put it in the body.It still doesnt work:s
it still gives:
1. Error Line 22, Column 37: document type does not allow element "img" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "address", "fieldset", "ins", "del" start-tag

<img src="banner.jpg" alt="banner" />

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

could you try it?
http://validator.w3.org/#validate_by_uri+with_options
thats the validator site.

What the...??It STILL gives me an error!!:(

Member Avatar for diafol

Sorry - I placed the img in a 'p' - worked fine. AFAIK - Strict needs all images to be placed in a container (usually a block level element). I wasn't aware of this previously and can't find any details on it. Change strict to transitional if you don't want to do this. It will validate fine in transitional.

Hmm...Il try placing it in a block level element.Actually, i have to use strict.but thanks for the help.Il try it out and see if it works then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.