---
title: "Discussion on \"All the Ways to Center a Div\" | Hashnode"
description: "Discussion on \"All the Ways to Center a Div\". Centering a div is something we need to do all the time as web developers, and yet it still can be a challenge. There are many approaches you can take to accomplish it. Below I'll explore all the ways to center one div inside another. \nAll of the exa..."
url: "https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [All the Ways to Center a Div](https://blog.katherinempeterson.com/all-the-ways-to-center-a-div?utm_source=hashnode&utm_medium=feed)

Centering a div is something we need to do all the time as web developers, and yet it still can be a challenge. There are many approaches you can take to accomplish it. Below I'll explore all the ways to center one div inside another. All of the exa...

Feb 28, 2021 · 3 min read · blog.katherinempeterson.com  
Updated Mar 11, 2021  
Read the article

-   [#web-development](https://hashnode.com/tag/web-development)
-   [#webdev](https://hashnode.com/tag/webdev)
-   [#css](https://hashnode.com/tag/css)
-   [#html5](https://hashnode.com/tag/html5)

## Written by

[Katherine Peterson](https://hashnode.com/@katherinecodes)

@katherinecodes · California, US

  
[View profile](https://hashnode.com/@katherinecodes)

Software Developer

## Responses 6

Markdown supported · ⌘↵ to post

[Savio Martin](https://hashnode.com/@saviomartin)

[Mar 2, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603e1d5e0490d8091f1beee0)

I have used them all, flexbox is my favorite

```
.flex{
  display: flex;
  justify-content: center;
  align-items: center;
}
```

I usually build a separate class with flexbox and reuse the same class in places I need flexbox 🙌

[Ganesh K S](https://hashnode.com/@Gani26)

[Mar 2, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603ddc3285584105b64b00f4)

u made it easy to understand...thanks

[Ai Anshu](https://hashnode.com/@aianshume)

[Mar 1, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603cf5f469a4e7019effaad1)

thanks for this information i allways search for this topic on stackoverflow

[Gourav Khunger](https://hashnode.com/@gouravkhunger)

[Mar 1, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603ceed669a4e7019effa962)

I always tend to forget the process to center divs 🤣 Good for me! Thanks for this article [Katherine Peterson](https://hashnode.com/@katherinep)

[Suraj kumar](https://hashnode.com/@hashsuraj)

[Mar 1, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603ce4ccb645547d6beaafad)

.outer-div { display: flex; justify-content: center; align-items: center; }

it is the best way instead of position

[Vivek Tiwari](https://hashnode.com/@vivek566)

[Mar 1, 2021](https://hashnode.com/posts/all-the-ways-to-center-a-div/603c0fb10dad7e6b99e21bc8/comment/603cd5ba1f91337d465bf015)

Flexbox is the easiest and my goto approach. 🙌
