How to horizontal align text content into center in HTML ?
Last Updated :
25 Dec, 2020
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:
Share your thoughts in the comments
Please Login to comment...