In HTML center text can be done using the HTML Center Tag. In other words we can say that whenever we want to align center any text in HTML we can use the HTML Center tag.
The HTML Center Tag is not supported in HTML 5 and is deprecated in HTML 4.0.1 hence we have to use CSS to HTML Center Text in any resource or webpage to align text at the center.
Syntax for HTML Center Text Tag
Some Text in beginning
<center>
Some text in center
</center>
Some text in the end
Example for HTML Center Text Tag
HTML Center Text Tag Code | Output |
This is a text in the beginning. <center>This is the text that will be centered.</center> This is the text at the end. |
This is a text in the beginning. This is the text at the end. |
Here in the HTML Center Text example we can see that the text written within the HTML Center tag is aligned to the center of the space available for the output to be displayed whereas the rest of the text is aligned to the left of the available space.
HTML Center Text Tag Supporting Attributes
HTML Center Text Tag Attribute Name | Value | Description |
class | classname | Indicates a classname for the tag |
dir | rtl, ltr | Indicates the text direction: right to left (rtl) and left to right (ltr). |
id | id | Defines a unique id for the tag |
lang | language_code | Indicates the language code for the language contained within the tag |
Style | style_definition | Indicates an inline style for the tag |
Title | text | Defines additional information about the tag |
See all HTML Global Attributes.
HTML Center Text Tag Supported Event Attributes
HTML Center Text Tag Event Attributes | Value | Description |
onclick | Script/code | Script/code to be executed on mouse click |
ondbclick | Script/code | Script/code to be executed on mouse double click |
onmousedown | Script/code | Script/code to be executed on mouse button is pressed |
onmousemove | Script/code | Script/code to be executed on mouse pointer moves |
onmouseout | Script/code | Script/code to be executed on mouse pointer moves out of the target element |
onmouseover | Script/code | Script/code to be executed on mouse pointer moves over the target element |
onmouseup | Script/code | Script/code to be executed on mouse button is released |
onkeydown | Script/code | Script/code to be executed on key press |
onkeypress | Script/code | Script/code to be executed on key pressed and then released |
onkeyup | Script/code | Script/code to be executed on key is released |
See all HTML Event Attributes
HTML Center Text Tag Supporting Browsers
S. No. | Browser | Supported(Yes/No) |
1 | Internet Explorer | Yes |
2 | Firefox | Yes |
3 | Google Chrome | Yes |
4 | Opera | Yes |
5 | Safari | Yes |