English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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>).
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 ‹/›
IEFirefoxOperaChromeSafari
All mainstream browsers support the <center> tag.
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.
Tip:Please use CSS styles to center text! You can learn more about it in the CSS tutorial.Centered textdetails.
HTML5 The <center> tag is not supported, HTML 4.01 The <center> tag is deprecated.
In HTML 4.01 The <center> tag supports the following standard attributes:
Attribute | Value | Description |
---|---|---|
class | classname | class name of specified elements |
dir | rtl ltr | text direction of content within specified elements |
id | id | Specify the unique id of the element |
lang | language_code | Specify the language code of the content within the element |
style | style_definition | Specify the inline style of the element |
title | text | Specify additional information for the element |
For a complete description, please visitStandard Attributes.
In HTML 4.01 In, the <center> tag supports the following event attributes:
Attribute | Value | Description |
---|---|---|
onclick | script | Execute script when the mouse is clicked |
ondblclick | script | Execute script when the mouse is double-clicked |
onmousedown | script | Execute script when the mouse button is pressed |
onmousemove | script | Execute script when the mouse pointer moves |
onmouseout | script | Execute script when the mouse pointer moves out of an element |
onmouseover | script | Execute script when the mouse pointer hovers over an element |
onmouseup | script | Execute script when the mouse button is released |
onkeydown | script | Execute script when the keyboard is pressed |
onkeypress | script | Execute script when the keyboard is pressed and then released |
onkeyup | script | Execute script when the keyboard is released |
For a complete description, please visitEvent Attributes.