Computer >> Computer tutorials >  >> Programming >> CSS

How to center your website horizontally with CSS?


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

Example

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
   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;}
</style>
</head>
<body>
<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>
</div>
</body>
</html>

Output

The above code will produce the following output −

How to center your website horizontally with CSS?