Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 comes before h1 in source, Is it ok? [closed]

IF i use <h2> for left sidebar heading and use <h1> for main center content area heading then actually in source and and if CSS is disabled , in both condition <h2> comes before <h1>.

Is it ok? or i should not use <h2> for left sidebar headings?

Update: 5 Feb

Example image added

Heading Structure http://easycaptures.com/fs/uploaded/235/1182330679.png

Why I'm asking because i always read in many articles <H1> should be the first heading in the page .

alt text http://www.crearecommunications.co.uk/seo-blog/wp-content/uploads/2009/11/heading-subheads.gif

like image 413
Jitendra Vyas Avatar asked Feb 04 '10 18:02

Jitendra Vyas


People also ask

Can we use H2 tag inside h1 tag?

According to all HTML specifications and drafts, an h1 element must not contain an h2 element.

How do you display h1 and H2 on the same line?

h1 and h2 are native display: block elements. Make them display: inline so they behave like normal text. You should also reset the default padding and margin that the elements have. Actually this solution solves the problem better than the one marked as the answer.

Does h1 have to be first?

Headers can be H1s, but they don't have to be. The main heading of a page can be an H1, but it doesn't have to be.

Why is my H2 bigger than h1?

font size values in a way that will follow the header hierarchy ( h1 has to be bigger than h2 , h2 has to be bigger than h3 etc.) because the current web layout has a slightly bigger font-size value for h2 than h1 .


6 Answers

Well, considering the semantics of the h-tags, it is not OK. Your headlines in the finished document should produce a document outline like

 1. H1-Head
     1.1 H2-Head
         1.1.1 H3-Head
         1.1.2 H3-Head
         ...
     1.2 H2-Head
         1.2.1 H3-Head
         ...
     1.3 H2-Head
     ...

and so forth.

Of course this outline should conform the chronology of the tag occurences.


Update for your update

I would suggest the following markup

<h1><a>Main title of your site</a></h1>
<h2>Sidebar</h2>
    <h3>Sidebar Headline 1</h3>
    <h3>Sidebar Headline 2</h3>
    ....  
<h2>Main content</h2>
    <h3>Headline 1</h3>
    <h3>Headline 2</h3>
    ...

Do you know the Firefox Web Developer Plugin? It has a function "Show document outline". There you can easily validate the logic of your markup. And to give you an idea, one good and one bad example from pfizer.com and phizer.de (I think you can get the idea, even if it is German - the headlines in red say "Missing Headline").

pfizer.com http://img246.imageshack.us/img246/1336/com.png


pfizer.de http://img96.imageshack.us/img96/1273/74591264.png

By the way: Having all that h-tags in your markup doesn't neccessarily mean that they all have to be visible ;-) !

like image 161
Leo Avatar answered Oct 07 '22 15:10

Leo


You should think about it semantically. H1 should come before H2 in a document. H2 is a sub element of H1.

The way I approach a page is to code it in HTML first so that it makes sense to a user without JavaScript and CSS enabledProgressive Enhancement .

Only, then do I worry about styling the content.

like image 34
easement Avatar answered Oct 07 '22 15:10

easement


probably best option would be to have actually the sidebar after the content in your html and use css to position it where you want.

like image 22
Michal M Avatar answered Oct 07 '22 16:10

Michal M


From browser's point of view, the order of the tags does not matter. However, the order of the h1 and h2 has semantic implications for the structure of your document. So, having them in the correct order does matter.

Of course, a modern web app does not consist of one document only. There are "external" panels, which are not part of the document (sidebars, panels and so on). Thus, if you want to be semantically "correct", you should reserve h1, h2 and the rest to the main content of your page only, and use div and span for block and inline containers, that do not belong to the semantic structure of your document.

like image 20
Franci Penov Avatar answered Oct 07 '22 17:10

Franci Penov


Semantically, you will want to have the <h2> tags to come after <h1> for the document outline. In this case - does the sidebar really make sense within the flow of the document headers?

From the structure you've described, it seems that the <h2> tag is being used as a header for content that may not be related to the content on a specific page. From a search engine optimization perspective, this may not be optimal if these headers are not actually used in context, but used for the styling.

this article can clarify a bit more: http://www.nathanrice.net/blog/ultimate-guide-to-wordpress-seo-optimized-heading-tags/

like image 43
ddango Avatar answered Oct 07 '22 15:10

ddango


I think people are being pedantic when they say the h1 must come before the h2 in the code. The h1 should be around the most important information on the page whether it is at the top or in the footer.

What is your focus? Are you promoting the company name or what the company does/sells?

I figure if the company is selling 'red widgets', I want 'Red Widgets' to be an h1 on the product page, 'Widgets' to be the h1 on the product listing page and 'We Sell the Best Red, White, and Blue Widgets!' to be the h1 on the home page.

If somebody is looking for 'red widgets', they are usually searching for 'red widgets' and not 'ThisWidgetCompanyName'. The 'ThisWidgetCompanyName' in the title tag will catch anyone searching for the company name and unless there are a lot of companies with the same name, they should pop up near the top.

like image 25
Emily Avatar answered Oct 07 '22 16:10

Emily