How to center your website horizontally with CSS?

CSSWeb DevelopmentFront End Technology

To center your website horizontally with CSS, the code is as follows −


 Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
   body {
      background: rgb(255, 238, 0);
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .main {
      max-width: 600px;
      margin: auto;
      background: rgb(70, 32, 240);
      color: white;
      padding: 10px;
   p {font-size: 40px;font-weight: lighter;}
<div class="main">
<h1>Center website horizontally example</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ad nemo, nisi fugiat dolores 
quidem ipsam, quisquam sit, quos amet provident accusantium. Ab cumque est ut officia libero, 
quis non quidem eaque eligendi iusto numquam, optio magni corrupti, eum ad. </p>


The above code will produce the following output −

Updated on 12-May-2020 14:33:53