Thursday, January 9, 2025
HomeProgrammingHow to center a button in CSS

How to center a button in CSS

To center a button in CSS:

  1. Flexbox (horizontal + vertical):
    css
    display: flex;
    justify-content: center;
    align-items: center;
  2. Grid (horizontal + vertical):
    css
    display: grid;
    place-items: center;
  3. Text Align (horizontal only):
    css
    text-align: center;
  4. Absolute Positioning (horizontal + vertical):
    css
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

Use the method that suits your layout!

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x