Languages
[Edit]
EN

CSS - text align right

0 points
Created by:
Laylah-Walsh
654

In this article, we would like to show you how to align text to the right using CSS.

Quick solution:

.element {
  	text-align: right;
}

 

Practical example

In this example, we create a style for  .element class that uses text-align property to align text inside div element to the right side.   

// ONLINE-RUNNER:browser;

<!doctype>
<html>
<head>
  <style>

    .element {
      	text-align: right;  /*  <---------- required   */
        border: 1px solid lightgray;
    }

  </style>
</head>
<body>
  <div class="element">Some text here...</div>
  <br />
  <div class="element">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. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</body>
</html>

Note:

You can also use text-align: end which is a new standard solution, however it is supported by all major browsers since 2020. For legacy purposes, we use text-align: right in the example.

 

See also

  1. CSS - text align left

  2. CSS - text align center

  3. CSS - text align justify

References

  1. text-align - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - move text to the right
  2. CSS - place text on the right
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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