html center a text code example

Example 1: html center text

<div style="text-align:center">Dieser Text wird zentriert.
<p>Ebenso dieser Paragraph.</p></div>

Example 2: html how to center text

<p style="text-align:center;">Centered paragraph.</p>

Example 3: html css center text on page

<style>
body { background: white }
section {
  background: black;
  color: white;
  border-radius: 1em;
  padding: 1em;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-right: -50%;
  transform: translate(-50%, -50%)
  }
</style>

<section>
  <h1>Nicely centered</h1>
  <p>This text block is vertically centered.
  <p>Horizontally, too, if the window is wide enough.
</section>

Example 4: center text in html

text-align: center;

Example 5: how to center text in html

<p><center>YourText</center></p>

Tags:

Html Example