
What if you don’t want all the text on the page to be centered, or your page contains images and other elements besides text? In that case, you’d use the same text-align property but a different CSS selector.įor example, say you want the headings centered on a page, but the paragraphs to be left-aligned. See the Pen Centering Text Using the Text-Align Property by HubSpot ( on CodePen.Ĭentering an HTML Element Type with the Text-Align Property

Then you’d set the text-align property to center. Then you could use the CSS universal selector (*) or the type selector body to target every element on the page. Say you have a text-only web page and want to center all the text. Centering Text Using the Text-Align Property Center-Align Text in CSSīelow, we go over several tutorials for centering text outside and inside other elements. But if you’re interested in centering an element type, such as all H1s in your blog, it’s better to do it in CSS.

You can also center text in HTML, which is useful if you only want to center individual elements on the page on a case-by-case basis. To center text in CSS, use the text-align property and define it with the value 'center.' You can use this technique inside block elements, such as divs.
