Languages
[Edit]
EN

CSS - specify text horizontal alignment

0 points
Created by:
nickkk0
467

In this article, we would like to show you how to specify text horizontal alignment with CSS.

Quick solution:

div {
    text-align: center;  /*  or: left | right | justify  */
}

 

Text alignment

By setting the text-align property we are able to align the inline content inside the element.

PreviewStyle

text-align: left (default)

Note:

You can also use text-align: start.

text-align: right

Note:

You can also use text-align: end.

text-align: center
text-align: justify

 

Practical example

In this section, we present various text alignments in the following order: left, right, center, justify.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>
    
    div {
        border: 1px solid gray;
        max-width: 230px;
    }

  </style>
</head>
<body>
  <p>left or start (default):</p>
  <div style="text-align: left">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
  <p>right or end:</p>
  <div style="text-align: right">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
  <p>center:</p>
  <div style="text-align: center">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
  <p>justify:</p>
  <div style="text-align: justify">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
</body>
</html>

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join