38

Is there any difference between

<body dir="rtl">

and

<body style="direction:rtl">

?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jonathan
  • 8,676
  • 20
  • 71
  • 101

1 Answers1

32

<body dir="rtl"> is more appropriate as per W3C recommendation:

http://www.w3.org/International/questions/qa-bidi-css-markup

Because directionality is an integral part of the document structure, markup should be used to set the directionality for a document or chunk of information, or to identify places in the text where the Unicode bidirectional algorithm alone is insufficient to achieve desired directionality. [...] You should therefore use dedicated bidi markup whenever it is available. Do not simply attach CSS styling to a general element to achieve the effect.

User-agents that ignore CSS will also benefit from this approach.

Luca
  • 9,259
  • 5
  • 46
  • 59
Mike Soule
  • 732
  • 1
  • 6
  • 11
  • 1
    I think this is a good answer, but a combination of both methods can give some styling power. For example you can (using CSS) float an element left or right depending on the class (.ltr or .rtl) – Jonathan Mar 28 '11 at 16:31
  • 6
    Once you have the html attribute, you don't need a class. You can use attribute selectors like `[dir=rtl]`, `:not([dir])` – Xavier Mar 23 '15 at 16:27