H1 and range

When using the h1-h6 tags in my html, I keep getting error messages on the w3c validator. I am new to this and I have tried many times to solve the problem, but I cannot.

On my website, the text looks great, but it will not be checked. How to solve this problem? The error message is as follows:

Row 34, column 4: the document type does not allow the element "h1" here; missing one of the "objects", "applet", "map", "iframe", "button", "ins", "del" start tag

<h1><span> My website </h1>< span> <---- is the code for which I am getting an error.

The specified item is not allowed to appear in the context in which you placed it; the other mentioned elements are the only two allowed there and may contain the said element. This may mean that you need a containing element, or it may be that you forgot to close the previous element.

One possible reason for this message is that you tried to place a block element element (for example, "

"or") inside an inline element (for example, "", "" or "").

Anyway, what's the best way to use header tags? What am I doing wrong?

+7
source share
6 answers
  • Span is an inline element
  • h1 is a block element
  • An inline element cannot contain a block element
  • Elements cannot be partially contained in other elements

Therefore, from the point of view of DTD:

 <h1><span></span></h1> <!-- This is fine --> <div><h1></h1></div> <!-- This is fine --> <h1><span></h1></span> <!-- This is wrong --> <span><h1></h1></span> <!-- This is wrong --> 

Which correct solution to the problem actually depends on what you are trying to use the range on.

(Note that the discussion of blocks and inline elements above is somewhat simplified. See How to read HTML DTD for a full story, specifically the section on Content Model)

+18
source

You close tags in the wrong order:

 <H1><span> My website </h1></span> 

it should be

 <h1><span>My website</span></h1> 
+9
source
 <h1 style="display:inline;">Bold text goes here</h1> <h2 style="display:inline;">normal text goes here</h2> 

use the above if you are looking at the built-in H1 tags

+3
source

you cannot spit on an element with another element

 < H1>< span> My website < /h1>< /span> 

must be specified

 < H1>< span> My website < /span>< /h1> 
+1
source

Did you try to write this?

 <h1><span> My website </span></h1> 

you must close the tags in the same order that you open them.

+1
source

Your items are not nested correctly.

Think of them as different types of brackets.

If <h1></h1> like {} , and <span></span> like [] , then you

  { [ My website } ] 

As you can see, the brackets are off.

Do you want to

  <h1><span>My website</span></h1> 
0
source

All Articles