# Ways to Center an Element in CSS
## Centering an Element Horizontally Using `margin: auto`
```css
margin:auto; display:block
```
## Centering an Element Horizontally Using `text-align: center`
```css
text-align: center;
```
## Centering an Element in the Viewport
This CSS will center an element both vertically and horizontally.
```css
position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%);
```
To center within a particular `div` skip the `position` property.