Open In App

How to horizontal align text content into center in HTML ?

Last Updated : 25 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads