

In this example, we used text-align: center property to the parent div and button position 50% from top "top: 50% ". The text-align property of CSS aligns the inline-level content (here button) to a horizontal alignment.

We have assigned the style information of the button using the HTML tag. Here, we discuss the code block in detail: In this example, we have used HTML and CSS to align the button on the web page to the center. In this example, we are using text-align: center property to the parent div and button position 50% from top "top: 50% ". Let us grab a look at this CSS code snippet and understand how to align the button to the center of the HTML page using CSS We use the text-align property with the parent div tag to align the button to the center. Center Button Vertically AND Horizontally 3.1: By setting the text-align property of the parent div tag to the center Margin auto moves the div to the center of the screen. In this example, we are using the `margin` auto property. Center CSS Button by using margin auto ( margin: auto) In this example below, we are using `text-align` center property on tag with a class ( button-container-div ) so everything inside this will be center-aligned automatically. Run Code 1.1 By setting text-align property of parent div tag to the center ( text-align: center) In this example, we are using `text-align` center property on the tag, so everything inside the tag will be center-aligned automatically. By placing a text-align property of body tag to the center (text-align: center) display: grid - By setting the display property to the gridġ.display: flex - By setting the display property to flex.

