Chat Editor
💡 Click messages to edit. Supports Markdown formatting.
Preview
How do I center a div in CSS?
There are several modern ways to center a div:
**1. Flexbox (Recommended)**
```css
.parent {
display: flex;
justify-content: center;
align-items: center;
}
```
**2. Grid**
```css
.parent {
display: grid;
place-items: center;
}
```
**3. Absolute Position**
```css
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
```
Flexbox is the most widely used and supported approach! 🎯