Step 1:Create index.html file and implement as below code in it.
<div class="center">
<p>Hello World! </p>
</div>
Step 2:Implement CSS code as below to set text center at the div element.
<style>
body {
background: #c7254e;
}
.center {
margin: auto;
width: 60%;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
Complete Code For Setting A Text Center Inside HTML Element Using CSS.
<!DOCTYPE html>
<html>
<head>
<title>How To Set A Text Center Inside HTML Element Using CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
body {
background: #c7254e;
}
.center {
margin: auto;
width: 60%;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
<body>
<br/><br/>
<div class="container">
<br>
<div class="text-center">
<h1 id="color" style="color: white;">Set A Text Center Inside HTML Element Using CSS</h1>
</div>
<br>
<div class="well">
<div class="center">
<p>Hello World! </p>
</div>
</div>
<br>
</div>
</body>
</html>