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"> GeeksforGeeks </h1> <h3 align="center"> How to horizontal align text content into center in HTML? </h3> <p align="center"> GeeksforGeeks: A computer science portal for geeks </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>GeeksforGeeks</h1> <h3> How to horizontal align text content into center in HTML? </h3> <p> GeeksforGeeks: A computer science portal for geeks </p> </body> </html> |
Output:
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.


