How to Align Button to Right, Left, and Center in CSS

Last Updated on December 25, 2024 by Roshan Parihar

In this tutorial, learn how to align button to the right, left, and center position using CSS. The short answer is: use the CSS text-align property. To use the property, you need to place the button inside the <div> element.

Let’s find out different ways of button alignment using CSS with the simple live examples given below.

How to Align Button to Left, Right, and Center Using CSS

You can easily position the button to left, right, and center position using CSS with the different ways as given here.

Left Align Button Using CSS text-align Property

Firstly, place the button inside the <div> element. After that, use the CSS text-align: left property as given below:

Output

Right Align Button Using CSS text-align Property

To right align button in CSS, you have to first place the button inside the <div> element. After that, use the CSS text-align: right property as given below:

Output

Center Alignment of Button in CSS

For center aligment of button, you have to place the button inside <div> element and use the CSS text-align: center property as given below:

Output

Left and Right Button Alignment on the Same Line Using CSS Float Property

If you want to align the buttons to the left and right position on the same line, you can use the CSS float property.

To move the button to the left position on the same line, you have to use the CSS float: left property. For the right position, you have to use this property as float: right.

Output


The most noteworthy thing here is that you cannot use this property to center align the button. The above example showing the left and right align buttons.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.