center (HTML element)
Example
The center
element is typically used in a menu:
<center> <h1>Lunch Menu</h1> <p>All food cooked fresh to order.</p> <h2>Starters</h2> ⋮ </center>
- Type
- block-level element
- Contains
- block-level elements, inline elements
- Contained by
applet,blockquote,body,button,center,dd,del,div,fieldset,form,iframe,ins,li,map,noframes,noscript,object,td,th
Description
The center
element almost needs no description—the clue to its purpose is right there
in its name! It centers content. This is a block-level element, so each
new center element you create will produce a new block
of content:
<center>This is centered</center> <center>So is this</center> <center>And this is centered too</center>
The above markup would render as shown in Figure 1.
Note that, unlike paragraphs that are set using the p element, margins don’t appear
above or below the three lines in this case.
This element was originally created by Netscape, but it was integrated into HTML 3.2 (the update to HTML 3, which hadn’t included this element) because it was so widely used online. It has since been deprecated in favor of using CSS for centering content.
Use This For …
The center
element could be wrapped around all the content on a page—an approach that
would affect not just the text, but the images and tables that are on the
page as well. There are not that many instances in which this kind of
effect is desirable or aesthetically pleasing, aside from the alignment of
items in a menu, as shown above. The best advice is to not use this
element, because it’s not present in the current HTML/XHTML (Strict)
standards, and thus it will cause the document in which it’s used to be
invalid. Instead, use CSS to center content: a div element may be used as a
wrapper for the content to which the CSS
text-align:center; is applied to take care of text
alignment.
Compatibility
| IE | 5.5 | Full |
|---|---|---|
| 6.0 | Full | |
| 7.0 | Full | |
| Firefox | 1.0 | Full |
| 1.5 | Full | |
| 2.0 | Full | |
| Safari | 1.3 | Full |
| 2.0 | Full | |
| 3.0 | Full | |
| Opera | 9.2 | Full |
| 9.5 | Full |
Every browser listed supports this element type.
User-contributed notes
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

