Styling Right-To-Left Text with CSS on a Multi-Lingual Site
We recently had the pleasure of working with CD Baby creator Derek Sivers on a new project called MusicThoughts. It’s a great collection of quotes from musicians on everything from the music industry to life in general. In short, pretty kick-awesome! Go check it out already!
This was a challenging project from start to finish. First of all, we couldn’t modify the HTML at all, only the CSS. And second was the support for multiple languages. 10 to be exact! This had several ramifications:
- Every piece of text had to be editable. For a design that was going to be largely photographic in nature, this was a huge challenge.
- Different languages take up different amounts of space, so the room we alloted for every bit of text, even the name of the site and navigation, had to shrink and grow appropriately.
- Some languages, like Arabic read from right to left. Holy crap! That changes everything about your design!

And it’s the last point I wanted to explore a bit more. You see, for languages that read from right to left there’s a dir="rtl" attribute that we can tie into with CSS so we can target it and style appropriately. Mr. Sivers put his on the html element:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ar" dir="rtl">
So for instance, the navigation got all messed up when it was text-aligned right. All we have to do is target it with CSS and make minor modifications:
html[dir="rtl"] #navigation {
float: right;
display: inline;
margin-left: 0px;
margin-right: 360px;
}
And that’s it! Rinse and repeat for the affected areas. Believe it or not, this targeting seems to be supported by all the major browsers (unheard of, I know!) so try it out on your next multi-lingual site and see how awesome it is.
1
David Cameron Walker
Mar 17, 2009
.(JavaScript must be enabled to view this email address)
Mar 17, 2009
.(JavaScript must be enabled to view this email address)
Mar 17, 2009
4
.(JavaScript must be enabled to view this email address)
Oct 12, 2009
5
.(JavaScript must be enabled to view this email address)
Oct 05, 2010
.(JavaScript must be enabled to view this email address)
Oct 05, 2010
7
Roberto Maurizzi
Dec 07, 2010
.(JavaScript must be enabled to view this email address)
Dec 07, 2010
9
.(JavaScript must be enabled to view this email address)
Nov 14, 2011