Home
CSS
CSS Align
Tryit: Horizontally center a block element
Run ❯
Get your
own
website
Result Size:
625 x 534
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <head> <style> .center { margin: auto; width: 60%; border: 3px solid #73AD21; padding: 10px; } </style> </head> <body> <h2>Center Align Elements</h2> <p>To horizontally center a block element (like div), use margin: auto;</p> <div class="center"> <p>Hello World!</p> </div> </body> </html>