the <center> html tagWebsites by Mark - 7 Woodrush gardens, Carterton, Oxfordshire. OX18 1JE

the <center> html tag
the <center> html tag

The <center> html tag

Overview

By default body text in a HTML document is aligned left, by using the <center> HTML tag you can make the text appeared centered within its surrounding tag. It is a widely used tags in HTML today. It works equally as well in table based layouts as well as CSS based ones. It was often used in the past to centre the content of <div> tags, but this is now usually dealt with purely in CSS. As with all older HTML tags it can be used in situations where consistancy between browsers is difficalt to acheive in other ways. When text is put between the opening and closing <center> tag it is displayed as a center text.

Basic Usage

<center>Some center text in here</center>
Any text between the opening and closing tag will be displayed as a center text.

Advance Usage

It is possible to style and add functionality to the <center> tag, this is done by adding an attribute to after the p in the opening <center> tag
Attributes allowed for the <center>tag include :-class, dir, id, lang, style and title.
In most cases class and id are used and its basic usage is shown below
<center id=”header”>Some center text</center>
With all attributes there is a space after the initial p 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 <center> tag may use either the id or class as an atribute.
The attribute style allows you to include css style information for a single <center> 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.
It is possible to attach scripts to tags, as well adding functionality to a webpage, these scripts tend to be written in Javascript and therefore outside the scope of this document

Examples

<center>Some center text</center> – basic usage example.
<center id=”header>Some center text</center> – center text which is styled by the id header.
<center class=”headerclass”> Some center text </center> – center text which is styled by the class headerclass.
<center id =”header” class=”headerclass”> Some center text </center> – center text which is styled by the class headerclass and the id header.
<center style="color:#F00">Some center text</center> – center text which has a custom colour of red.
<center dir="rtl">Some center text</center> – center text where the text reads from right to left.
<center lang="uk">Some center text</center> – center text where the language has been tagged as UK.
<center title="ptitle">Some center text</center> – center text where the tag has been titled ptitle.

Final Thoughts

Touching on just the surface of the <center> HTML tag it is easy to see how versatile it is. To take full advantage of it an understanding of CSS is an advantage.

Website for £99

Offers

 

Categories

 

Our blog

Some random stories from our blog.

The <div> html tag

Overview In simple terms the <div> HTML tag stands for division. It is one of the most widely used tags in HTML today. With the use of CSS it allows virtually any design to be created. Prior to the <div> tag, layout was created using the <table> tag. Div based layouts are considered to be better than table based layouts due to a number of factors including accessibility and SEO. As mentioned CSS allows this tag to create virtually any layout, but due to differences between how internet browsers support CSS, a consistant result can be harder to acheive.When text is put between the opening and closing <div> tag it is displayed as a Division. Basic Usage <div>Some div text in here</div> Any text between the opening and closing tag will be displayed as a Division. Advance Usage It is possible to style and add functionality to the <div> tag,…

Accessible web design – an oxymoron

The <tt> html tag

Apple to buy Google

How expensive is your free marketing?

© 2011 Websites by Mark. Do not reproduce any part of with website without permission.
Email : mark@websitesbymark.co.uk - Phone : 07716 447228 / 01993 221500
Postal Address : 7 Woodrush Gardens, Carterton, Oxfordshire. OX18 1JE