How to horizontal align text content into center in HTML ?
In this article, we will align the text content into center using HTML. We use align=”center” attribute to set the text content into center.
Syntax:
<element_name align="center"> Contents... <element_name>
The align=”center” attribute is used to set the text content into center.
Example 1:
HTML
<!DOCTYPE html> < html > < head > < title > How to horizontal align text content into center in HTML? </ title > < style > h1 { color: green; } </ style > </ head > < body > < h1 align = "center" > w3wiki </ h1 > < h3 align = "center" > How to horizontal align text content into center in HTML? </ h3 > < p align = "center" > w3wiki: A computer science portal for Beginner </ p > </ body > </ html > |
Output:
Example 2: Use CSS text-align=”center” property to set the text content into center.
HTML
<!DOCTYPE html> < html > < head > < title > How to horizontal align text content into center in HTML? </ title > < style > body { text-align: center; } h1 { color: green; } </ style > </ head > < body > < h1 >w3wiki</ h1 > < h3 > How to horizontal align text content into center in HTML? </ h3 > < p > w3wiki: A computer science portal for Beginner </ p > </ body > </ html > |
Output: