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?
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.
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.
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.
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).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With