Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direction (LTR/RTL): What's the difference between the CSS direction and HTML direction attribute?

Tags:

html

css

Is there any difference between

<body dir="rtl"> 

and

<body style="direction:rtl"> 

?

like image 559
Jonathan Avatar asked Mar 21 '11 09:03

Jonathan


People also ask

What is LTR and rtl in CSS?

The direction CSS property sets the direction of text, table columns, and horizontal overflow. Use rtl for languages written from right to left (like Hebrew or Arabic), and ltr for those written from left to right (like English and most other languages).

What is LTR and rtl in HTML?

ltr. Default. Left-to-right text direction. rtl. Right-to-left text direction.

What does rtl mean in HTML?

Add dir="rtl" to the html tag any time the overall document direction is right-to-left (RTL). This sets the default base direction for the whole document. All block elements in the document will inherit this setting unless the direction is explicitly overridden.

What is the use of direction attribute in HTML?

Definition and Usage The dir attribute specifies the text direction of the element's content. The dir attribute can have the following values: ltr - means left-to-right text direction. rtl - means right to left text direction.


1 Answers

<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.

like image 130
Mike Soule Avatar answered Sep 22 '22 21:09

Mike Soule