Last updated September 17, 2011. Created by jwuk on January 10, 2006.
Edited by Jacine, bekasu, Jeff Burnz, Carolyn. Log in to edit this page.
Semantic (X)HTML elements convey meaning. Semantic markup combined with CSS is also the primary way to separate content from presentation. In essence semantic HTML is HTML minus the presentational HTML elements and attributes.
In the bad old days we used HTML for presentation, such as font, strike and u elements. The problem was that those elements didn't tell us anything about the meaning of the content.
POSH
POSH is the acronym for Plain Old Semantic HTML. POSH gives us an easy to remember acronym that encapsulates the simplicity, best practice and benefits of using semantic markup. You can learn more about POSH on microformats.org.
Humans vs Machines
Semantic markup is primarily for machines. While machines may be able to derive meaning from text, they can do this more easily by understanding the context in which the text appears. That context is semantic HTML.
Validation
It is a primary tenant of semantic (X)HTML that markup is valid.
Online validators look at the headings in the order they are in the content as delivered to the browser. You can place content in one order then use CSS to display the content in another order. The validator will look at the original order.
A common problem is to have a left hand sidebar before all other content and to have the sidebar start with an h2 element. The h2 appears before the h1 for the site name. The theme will fail WCAG (WAI) validation at level AA1.
There are theme examples at D-theme.com with validation buttons at the bottom of the page.
Accessibility
Place content first (content source ordering) then the sub headings and sidebars. In this structure, you can make the page title the h1.
For the visually impaired, the page title is more important than the site name on every page except the home page. When they search for example
, they want a site that starts off by saying example.com
. When they search for Orange and chilli salmon
, they want pages titled Orange and Chilli Salmon
, not example.com
.
Visually impaired people want the summary in the first paragraph and as the first content downloaded so they can find out if they are at a useful page. Some search engines place a greater weight on the first paragraph in the page. Improvements for visually impaired people should help with SEO. Your mileage may vary. Do not try this at home without adult supervision. Etc. Etc.
h1 as Site title or Page Title
The old HTML standard has an example showing the page subject as the h1 title. The HTML standard says A heading element briefly describes the topic of the section it introduces.
. A page title introduces the page, not the site, on every page except the home page.
It is therefore legitimate to use h1 for the site name on the home page and h1 for the page title on other pages. If the home page uses the site name as the page title then it briefly describes the topic ... it introduces
.
Drupal allow you to use a page-front.tpl.php file or use of the $is_front variable in conditional statements. Many Drupal themes make use of this to show the Site name in an h1 on the homepage (and/or other pages with no page title) and in a div or span for all other pages.
POSH Reference
This is a list of semantic (X)HTML elements with notes on usage. Please feel free to add to this or debate my explanations.
Block Elements
- div
- Provides meaningful divisions. Frequently nested and used to group related elements and content such as headers, sidebars, content area and footers.
- h1-h6
- The six levels of headings are used to introduce and describe sections of content. It is common practice to use only one h1 element on any one page—a page has one main heading and many sub sections with h2 and/or h3 headings.
- p
- The paragraph element is used to markup and deliniate a block of text.
- blockquote
- Indicates a large or substantial quote.
- address
- Indicates contact information for a document or a major part of a document. May be used in conjuction with the hCard microformat.
List Elements
- ul, ol, li
- Lists are used to represent grouped information best represented as a list. Often used to markup menus (a list of links). ol represents ordered list while ul represents unordered lists. li represents a single list item. Lists can be nested.
- dl, dd, dt
- Indicates a list of terms (dt) with their accompanying definitions (dd). Often used to markup FAQ's.
Inline Elements
- a
- Typically used with an href attribute to indicate an external resource or an anchored location within the same document.
- abbr
- Indicates a shortened form of a term or phrase. Often attributed with a title.
- acronym
- Used to markup acronyms, initialisms, and alphabetisms. Often attributed with a title.
- em
- Used to indicates emphasis. Emphasized text is in some way more significant than the text surrounding it.
- strong
- Used to indicate stronger emphasis. Similar to em but stronger.
- cite
- Indicates bibliographical information, personal quotations or references.
- code
- Indicates a sample of computer programming code.
- dfn
- Defines the first instance of a term in a document. The semantic value of dfn is debatable.
- del
- Indicates information which has been deleted from a document. Semantic replacement for the deprecated strike element.
- ins
- The opposite of del. Indicates inserted text added during revisions.
- samp
- Sample output from computer programs or scripts. Sample output may or may not be code.
- span
- Generic inline element used where a semantic element would be inappropriate. Span elements are considered to have no semantic value.
- q
- Indicates an inline quotation.
- kbd
- Indicates text to be entered by the user. Rarely used, but useful in circumstances where you are demonstrating the use of a program, along with code and samp.
- sub, sup
- Superscripting and subscripting of text. Often used to indicate footnote references.
- var
- Along with code, samp, kbd, the “variable” element indicates a variable (or program argument).
Form Elements
- label
- The label element is used to describe form elements.
Table Elements
- table
- Used to markup indicate tabular data.
- thead
- Defines a header region for a data table, which would normally contain the headers (th) for each column.
- tfoot
- Defines a footer region for a data table, which should include information referential to the columns of data.
- tbody
- The content region of a table.
- caption
- Describes the table. Essentially a heading for the table.
- th
- Table heading for rows columns. Indicate the type of information within the row or column.
- td
- A data cell, in which content is placed which corresponds to both the headers for the row and column.
View a default rendering of XHTML structural tags (for browser comparison).
Footnotes:
http://www.w3.org/TR/WCAG10-HTML-TECHS/#document-headers ↑
Comments
Site name and page title
If you are not printing your Site Name (Drupal 5.x), and only using a logo as branding, then you should probably modify page.tpl.php so that you end up with only one h1 headline on the page and have that headline be your PAGE TITLE.
If you don't do that, you end up with no h1 header and a bunch of h2 headers for block titles... and for your page title. Your page title should definately get some emphasis.
Open your page.tpl.php template file in a text editor and go to the markup generated for the page title.
You will find page.tpl.php in your theme folder.
For Garland, go to line number 68. The original line of code is :
<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>Change that to :
<?php if ($title): print '<h1'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h1>'; endif; ?>Then style your h1 headline appropriately.
If I were you, I would even add a class : page-title, and use it for styling.
<?php if ($title): print '<h1 class="page-title'. ($tabs ? ' with-tabs"' : '') .'>'. $title .'</h1>'; endif; ?>Caroline
A coder's guide to file download in Drupal
Who am I | Where are we
11 heavens
Caroline
11 heavens.com
An alternative opinion.
There has been many requests from people (especially SEO pundits) saying that H1 should be for Page titles, not Site titles and that the current usage is Not semantic according to W3C recommendations (Using h2 is a legacy habit from before CSS because H1 was too ugly).
I too believe that starting the H numbering from 'sitename' is wrong.
Others have other opinions.
Currently it's up to the theme designers, and you can make your own choices by using the hack above. Which is not the best situation. I think the recommendations on this page as "Semantic Best Practices" should be reviewed - although I've not seen consensus on it within the Drupal devs yet.
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Agree with dman. H1 should
Agree with dman. H1 should be the page title and not the site name.
page title as h1 for the visually impaired
See the addition titled Validation. For the visually impaired, you can make the page title h1 on every page after the page title.
petermoulding.com/web_architect
One and Only one H1
I believe it's also important to ensure that there is only one H1 tag on any given web page. Otherwise it is confusing to screen readers.
REVISION NOTE: This is also against WCAG 2.0 standards. Seems pretty clear from here that it should be the page title and not the site title - http://www.w3.org/TR/WCAG20-HTML-TECHS/H42.html
I would appreciate it of the original author would post some sources.
--
OpenConcept | Twitter @mgifford | Flattr
H1 for page title
For the sake of Usability and H1 should contain page title. When you look for information on google, you don't care about website's title, what cares the most is the page on that website containing the relevant information you are looking for. Google places high importance on the first major heading on a page – the logic being that Google expects it to contain some prime keywords about the information contained within that page.
Following that concept it turns pretty easy to determine where should the H1 tag be used.
__
Kenny Abarca | Drupal Dev/Business Owner
www.anexusit.com
I completely agree with this.
I completely agree with this. H1 is for the document name; not the sitename.
There is even an article from the W3C about this: Use <h1> for top-level heading.
IMO the sitename should be in a <div id="sitename"> or similar.
Missed tags
I'd like to remind the tag fieldset which are often used by drupal as block or part of form elements.
artemshymko.com