Skip to content
Related Articles

Related Articles

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:



Example 2: Use CSS text-align=”center” property to set the text content into center.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :