English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete List of HTML Tags

HTML: <center> Tag

The HTML Center element ( <center>) is a block-level element that can contain paragraphs, as well as other block-level and inline elements. The entire content of this element is centered horizontally in its parent element (usually <body>).

Online Example

Center the text horizontally in an HTML web page:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Tutorial Website(w3(codebox.com)</<title> 
</<head>
<body>
<center>This text will be centered.
<p>So will this paragraph.</p></center>
<div style="text-align:center>This text will be centered.
<p>So will this paragraph.</p></div>
Note: Applying text-align:center will center the content of these elements while maintaining their overall size.
</body>
</html>
Test and see ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <center> tag.

Tag definition and usage instructions

HTML5 The <center> tag is not supported. Please use CSS instead.

In HTML 4.01 In it, the <center> element is deprecated.

The <center> tag centers the text it includes horizontally.

Tips and Notes

Tip:Please use CSS styles to center text! You can learn more about it in the CSS tutorial.Centered textdetails.

HTML 4.01 with HTML5differences

HTML5 The <center> tag is not supported, HTML 4.01 The <center> tag is deprecated.

Standard Attributes

In HTML 4.01 The <center> tag supports the following standard attributes:

AttributeValueDescription
classclassnameclass name of specified elements
dirrtl
ltr
text direction of content within specified elements
ididSpecify the unique id of the element
langlanguage_codeSpecify the language code of the content within the element
stylestyle_definitionSpecify the inline style of the element
titletextSpecify additional information for the element

For a complete description, please visitStandard Attributes.

Event Attributes

In HTML 4.01 In, the <center> tag supports the following event attributes:

AttributeValueDescription
onclickscriptExecute script when the mouse is clicked
ondblclickscriptExecute script when the mouse is double-clicked
onmousedownscriptExecute script when the mouse button is pressed
onmousemovescriptExecute script when the mouse pointer moves
onmouseoutscriptExecute script when the mouse pointer moves out of an element
onmouseoverscriptExecute script when the mouse pointer hovers over an element
onmouseupscriptExecute script when the mouse button is released
onkeydownscriptExecute script when the keyboard is pressed
onkeypressscriptExecute script when the keyboard is pressed and then released
onkeyupscriptExecute script when the keyboard is released

For a complete description, please visitEvent Attributes.