codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › CSS align

CSS align

Center and align in several ways.

Horizontal: margin:auto or text-align:center. Vertical and both: flexbox align-items and justify-content, or place-items:center in grid.

Example code

<style>.c{display:grid;place-items:center;height:140px;background:#eee}</style>
<div class='c'>Centered both ways</div>

Run this code in the online editor

← CSS inline-blockCSS combinators →