

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to center a button element vertically and horizontally with CSS?
To center a button vertically and horizontally with CSS, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .centered { display: flex; justify-content: center; align-items: center; height: 200px; border: 3px solid rgb(0, 70, 128); } button{ font-size: 18px; border: none; padding:10px; background-color: darkblue; color:white; } </style> </head> <body> <h1>Centering Example</h1> <div class="centered"> <button>This button is centered</button> </div> </body> </html>
Output
The above code will produce the following output −
- Related Questions & Answers
- How to center an element vertically and horizontally with CSS?
- Center an element vertically in CSS
- How to center your website horizontally with CSS?
- How do I center text horizontally and vertically in a TextView of Android?
- Repeat the background image both horizontally and vertically with CSS
- How to horizontally center a widget using a grid() in Tkinter?
- How to center an annotation horizontally over a point in Matplotlib?
- How to center an image with CSS?
- Set element to center with Bootstrap
- How to create a search button with CSS?
- Center an image with CSS
- How to horizontally center a <div> in another <div>?
- Set the content of the label horizontally and vertically centered in Java
- Set the flex items horizontally with CSS
- With CSS add transparency to a button
Advertisements