In CSS, using the center
value with the text-align
property, you can make the contents of that element in the center. In this tutorial, we will see how to use the text-align center CSS property to make the things in center.
CSS text-align Property Syntax
text-align: center;
CSS text-align Examples
Make the paragraph text center-aligned
To make the text center for a paragraph use the following CSS code:
p { text-align: center; }
Make all h2 heading in the center
To align all the h2
headings in the page, use the h2
tag and the text-align
property with center
value:
h2 { text-align: center; }
Make Tabel headers and Footers Text in center
tbody th { text-align: right; } thead th { vertical-align: bottom; } tfoot th { vertical-align: top; } thead th, tfoot th { text-align: left; }
So here we have given some examples of the CSS text-align center to make the contents of an element in the center.