Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

h1 and the span

Tags:

html

tags

While using h1-h6 tags in my html, i keep getting error messages on w3c validator. I'm new to this and I've tried so many times to solve the problem but i can't.

The text appears perfectly fine on my website but it won't validate. How do i solve this problem? The error message is as follows;

Line 34, Column 4: document type does not allow element "h1" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

<h1><span> My website </h1>< span> <----this is the code i'm getting the error for.

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 "

" or "") inside an inline element (such as "", "", or "").

In any case what's the best way to use header tags? What am I doing wrong?

like image 544
Richard Avatar asked Dec 22 '10 19:12

Richard


People also ask

What does a H1 tag represent?

The H1 is an HTML (Hypertext Markup Language) heading tag that indicates the main topic on a web page. When visitors to your website see the H1s, it draws attention as it stands out the most on the page as it generally appears as a larger font size than normal text style and in bold.

What does the tag span mean?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.

What should be the length of H1?

H1 heading length. You should avoid making the H1 heading too long. If you do, there's a big chance the H1 heading won't be readable for your visitors, which hurts their user experience. We recommend sticking to a maximum length of 60 characters , similar to the title attribute.

Where should H1 tags be placed?

Your website should have only one h1 tag. If you have more than one h1 tag on a page, change the other h1 tags to an h2 or h3. Your h1 tag should be at the top of the page content (above any other heading tags in the page code).


1 Answers

  • An span is an inline element
  • An h1 is a block element
  • An inline element cannot contain a block element
  • Elements cannot be partially contained by other elements

Therefore, from the perspective of the 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 -->

What the right solution to the problem actually is rather depends on what you are trying to use the span for.

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

like image 196
Quentin Avatar answered Oct 15 '22 01:10

Quentin