Skip to main content

Centering a Text Inside a Button

· One min read
Anand Raja
Software Developer
Anand Techie
Software Developer, JS Specialist

Instead of centering headings and paragraphs, let’s center text inside another element (<button> </button>). Aligning the button, and the text inside the button, would differ slightly from the examples.

That’s because the text-align property only works on the content inside block-level elements, such as headings and paragraphs, and not inline elements, such as buttons.

So here's what we'll do instead:

  • Wrap the button in a div
  • Then, add an inline style declaration to the div, i.e. <div style="text-align:center">.
<div style="text-align:center">
<button type="button" class="btn btn-primary">Click Me</button>
</div>