---
title: "Align an element of a div to the center"  
description: "Align an element of a div to the center"  
author: "Anonymous User"  
published: 2021-07-20  
updated: 2021-07-20  
canonical: https://www.mindstick.com/forum/156546/align-an-element-of-a-div-to-the-center  
category: "css-css3"  
tags: ["html", "css-css3"]  
reading_time: 2 minutes  

---

# Align an element of a div to the center

How to center a [div element](https://www.mindstick.com/forum/34450/remove-div-element) [vertically and horizontally](https://www.mindstick.com/forum/156630/center-an-element-vertically-and-horizontally-with-the-help-of-bootstrap)?

## Replies

### Reply by Ethan Karla

You can easily an element of a div using display-flex property.

The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning.

Let's understand it with the help of an example :

```
<!DOCTYPE html>
<html lang ='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>Flexbox</title>
    <style>
        body {
            margin-left: 30%;
            margin-right: 30%
        }
        .d-flex {
            display: flex;
        }
        .justify-content-center {
            justify-content: center;
        }
        #square {
            width: 100px;
            height: 100px;
            background : black;
        }
        .flex-column {
            flex-direction: column;
        }
        .align-items-center {
            align-items: center;
        }
    </style>
</head>
<body>
    <div class='d-flex justify-content-center flex-column align-items-center'>
        <h3>Flexbox Property</h3>
        <p>This paragraph and below square will be centered</p>
        <div id='square'></div>
    </div>
</body>
</html>
```

Hope this information will be helpful for you.

Happy Coding!


---

Original Source: https://www.mindstick.com/forum/156546/align-an-element-of-a-div-to-the-center

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
