How to centre buttons horizontally within a div element

I was struggling to find a suitable, responsive, solution for this problem that would work when the number of buttons was variable. I was fortunate enough to run across this entry which solved my problem.

<div style='display:flex;justify-content:center;'>... buttons go here ...</div>

or, if you want to use CSS:

.centredButtonHolder {
  display: flex;
  justify-content: center;

<div class='centredButtonHolder'>... buttons go here ...</div>

Yes, I am aware that this will work with more than just buttons, but buttons are the items I have had issues with the most.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s