text-align: start & RTL

By  on  

As you've probably heard me mention a billion times on Twitter, I've been proudly work on the Mozilla Developer Network revamp.  This is my first real experience with working on websites with a fair amount of RTL readers. One thing I quickly recognized when browsing in RTL mode was that text wasn't always lining up on the correct side -- I would see text on the left where the browser should have displayed it on the right.  After digging into the stylesheets, I saw explicit text-align:left directives and started queueing up selectors I'd need to change to text-align: right.  Before doing so, however, I took the time to research a better way...and found it quickly.

text-align: left; /* as backup */
text-align: start;

text-align: start allows the browser to decide how to best align text based on the user's LTR or RTL preference.  There's also an "end" value if you prefer the text to show up on the right in LTR mode, and visa versa.  Browser support is good at this point, with Internet Explorer supporting this property within IE10.

Even if RTL isn't a requirement of your website, keep text-align: start in mind -- it's a very simple change that could be a big boost to your RTL visitors!

Recent Features

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

  • By
    Use Custom Missing Image Graphics Using Dojo

    A few months back I posted an article about how you can use your own "missing image" graphics when an image fails to load using MooTools and jQuery. Here's how to do the same using Dojo. The HTML We'll delegate the image to display by class...

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

Discussion

  1. Brian Compton

    Great tip. I was looking up RTL when I finally got it from the context: Right to Left languages such as Arabic, Hebrew, et al as opposed to LTR or Left to Right languages such as English.

  2. I developed fair amount of Arabic websites. I always add: body { direction:rtl; }

    And this fixes everything. I don’t need to even addwhatever { text-align:right; }
    I’ve tried to use this new rule but I couldn’t feel any difference. I don’t really know how it helps RTL websites! On the MDN it says:

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

    • I’ve not had the same experience Alfy, but I’ll look some more. “start” seems more semantically correct as well.

  3. Nice tip David,
    As an Arab developer , I agree with ahmed that using the proper direction and text-align is better, because most of people here uses English browsers/OS so the default text align for most of the visitors will be left. Another approach for multi language websites is to include additional style sheet i.e rtl.css or ltr.css .

  4. It simply make the process of localizing websites from an LTR language to a RTL one less painful, since you won’t need to go down the stylesheet and switch every right with left and vice versa in text-align properties.

    And I agree that it IS semantically more meaningful, for what graphic designer originally meant was that some text should be aligned through the end of the line. Which defers in direction for different languages.

  5. Wow! I am not a big commenter (at least not till I’m done with my site) but I had to say THANK YOU!! This property is not on the CSS3 site, so I figured there was no other way. It pays to be persistent, and your post proves that! Keep up the good work!!

  6. Binyamin

    IE10 actually does not support start and end value.
    Browser compatibility https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#Browser_compatibility

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!