How to center a button in CSS?CSS is mainly used for providing the best style to the HTML web page. Using CSS, We can specify the arrangement of elements on the page. There are various methods of aligning the button at the center of the web page. We can align the buttons horizontally as well as vertically. We can center the button by using the following methods:
Let's understand the above methods by using some illustrations. ExampleIn this example, we are using the text-align property and set its value to the center. It can either be placed in a body tag or in the parent div tag of the element. Here, we place the text-align: center; in the parent div tag of the button element. Test it NowOutput ExampleIn this example, we are using the display: grid; property, and margin: auto; property. Here, we place the display: grid; in the parent div tag of the button element. The button will place at the center of the horizontal and vertical positions. Test it NowOutput ExampleIt is another example of placing the button at the center. In this example, we are using the display: flex; property, justify-content: center; property, and align-items: center; property. This example will help us to place the button at the center of the horizontal and vertical positions. Test it NowOutput Next TopicHow to change background color in CSS |