HTML <center> tag (deprecated)S2C Home   « HTML <center> tag

Definition

The <center> tag is used for centering text.

The CSS text-align property allows this with more control, so use that instead.

Example


<center>This text will be centered.</center>

Required Attributes

NONE

Optional Attributes

NONE

Common Attributes

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<center class="classname">Some text here</center>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<center id="idname">Some text here</center>

style - specifies an inline style for the element allowing you to apply the style to the content.


<center style="color:red;text-align:left">Some text here</center>

title - specifies extra information about the content.


<center title="information about the content">Some text here</center>

Language Attributes

dir - specifies the directional flow of the content.


<!-- The text will flow from left to right -->
<center dir="ltr">Some text here</center>

<!-- The text will flow from right to left -->
<center dir="rtl">Some text here</center>

lang - specifies a language code for the content of the element.


<center lang="en">Some text here</center>

Document Event Attributes

NONE

Form Event Attributes

NONE

Image Event Attributes

NONE

Keyboard Event Attributes

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<!-- Executes the go() function -->
<center onkeydown="go()">Some text here</center>

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<!-- Executes the go() function -->
<center onkeypress="go()">Some text here</center>

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<!-- Executes the go() function -->
<center onkeyup="go()">Some text here</center>

Mouse Event Attributes

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<!-- Executes the go() function -->
<center onclick="go()">Some text here</center>

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<!-- Executes the go() function -->
<center ondblclick="go()">Some text here</center>

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<!-- Executes the go() function -->
<center onmousedown="go()">Some text here</center>

onmousemove - The JavaScript code to be run when the mouse button is moved.


<!-- Executes the go() function -->
<center onmousemove="go()">Some text here</center>

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<!-- Executes the go() function -->
<center onmouseout="go()">Some text here</center>

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<!-- Executes the go() function -->
<center onmouseover="go()">Some text here</center>

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<!-- Executes the go() function -->
<center onmouseup="go()">Some text here</center>

go to home page Homepage go to top of page Top