CSS Properties: How to set the text alignment for elements

Go to Exercise page


HTML Code:

<!DOCTYPE html>
  <title>How to set the text alignment for elements</title>
  <style type="text/css">
 h1 {
    text-align: center;

h2 {
    text-align: left;

h3 {
    text-align: right;
  <p><strong>w3resource Tutorial</strong></p>
  <h1>w3resource web development tutorial</h1>

<h2>w3resource web development tutorial</h2>

<h3>w3resource web development tutorial</h3>


Live Demo :

See the Pen text-align-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.