The h2 html tag
In HTML h tags stand for heading and this is split into 6 different h tags (h1, h2, h3, h4, h5 and h6). The <h2> tag itself is considered to be the main repeating heading for a webpage. By default it is displayed much larger than the body text but smaller than the main <h1> header. As with all h tags it is considered important for SEO.When text is put between the opening and closing <h2> tag it is displayed as a large heading. Unlike <h1> a <h2> tag can be used multiple times on a webpage as its job is to be the heading for a web pages main sub topics.
<h2>Large header text</h2>
Any text between the opening and closing tag will be displayed as a large heading.
It is possible to style and add functionality to the <h2> tag, this is done by adding an attribute to after the h2 in the opening <h2> tag
Attributes allowed for the <h2>tag include :-class, dir, id, lang, style and title.
In most cases class and id are used and its basic usage is shown below
<h2 id=”header”>Large header text</h2>
With all attributes there is a space after the initial h2 then the attribute name, then an equal’s sign and the identifier of the attribute in double quotes.
Both id and class attributes refer to CSS styling of the element and is either stored in the <head> of the webpage on in an external file.
With id this usually refers to a single instance on a page where as class usually refers to a repeating element on a page, it is for this reason for the <h2> tag the class attribute is nearly always used over the id attribute although in practice it makes no difference.
The attribute style allows you to include css style information for a single <h2> tag.
The dir attribute allows for left reading and right reading text, lang allows you to specify a language for the tag and title allows you to include extra information for a tag.
<h2>Large header text</h2> – basic usage example.
<h2 id=”header”>Large header text</h2> – heading 2 which is styled by the id header.
<h2 class=”headerclass”> Large header text </h2> – heading 2 which is styled by the class headerclass.
<h2 id =”header” class=”headerclass”> Large header text </h2> – heading 2 which is styled by the class headerclass and the id header.
<h2 style=”color:#F00″>Large header text</h2> – heading 2 which has a custom colour of red.
<h2 dir=”rtl”>Large header text</h2> – heading 2 where the text reads from right to left.
<h2 lang=”uk”>Large header text</h2> – heading 2 where the language has been tagged as UK.
<h2 title=”ptitle”>Large header text</h2> – heading 2 where the tag has been titled ptitle.
Touching on just the surface of the <h2> HTML tag it is easy to see how versatile it is. To take full advantage of it an understanding of CSS is an advantage.