Search code examples
csstext-alignment

Difference between text-align: end and right


What is the difference between text-align: end; and text-align: right;?

When I use either one I get the same result, but is there any differences?


Solution

  • According to https://developer.mozilla.org/en/docs/Web/CSS/text-align:

    • end
      The same as right if direction is left-to-right and left if direction is right-to-left.

    • right
      The inline contents are aligned to the right edge of the line box.

    Basically you use end in tandem to direction: [rtl|ltr] and end will adjust accordingly, whereas right will always keep your text to the right no matter what direction you set.

    https://jsfiddle.net/ths4kdmx/

    .end {
      text-align: end;
    }
    .right {
      text-align: right;
    }
    .dir-ltr {
      direction: ltr;
    }
    .dir-rtl {
      direction: rtl;
    }
    <div class="dir-ltr end">
      End alignment in left-to-right direction
    </div>
    <div class="dir-rtl end">
      End alignment in right-to-left direction
    </div>
    <div class="dir-ltr right">
      Right alignment in left-to-right direction
    </div>
    <div class="dir-rtl right">
      Right alignment in right-to-left direction
    </div>