Attribute dir, html or css

8

The dir attribute is usually omitted for LTR and is used for RTL - which are written from right to left (arabic and related), with the purpose of changing the direction, but I did not find anything relevant besides.

Using PHP to find the direction , you can use the browser language and files to load the settings. If you use CSS to change it, you would only need to combine a class with the same language name, and this would end up easing a lot of the process.

// css
.en_US, .pt_BR{direction:ltr}
.eg{direction:rtl}

// html
<body lang="pt_BR" class="pt_BR">

Question

Can we omit and maintain direction using only CSS ( direction:rtl ), or does the dir attribute have any other application?

I've tested screen readers, but at the time I did not pay attention to that. Do they identify the direction of the text by the attribute, or are they preconfigured?

    
asked by anonymous 02.11.2014 / 11:42

1 answer

4

Question 1:

  

I've tested screen readers, but at the time I did not pay attention to that. Do they identify the direction of the text by the attribute, or are they preconfigured?

Neither one nor the other. They do not read based on direction, but rather on the order in which the texts appear in the HTML source code (from beginning to end). [View Reference]

Question 2:

  

Can we omit and maintain the direction using just the CSS (direction: rtl), or does the dir attribute have any other application?

They have the same application, according to W3C specification. However, preferably use the dir attribute, according to W3C recommendation :

  Since direction is an integral part of the document structure, a markup should be used to determine the direction of a document or piece of information, or to identify points in the text where the bidirectional algorithm is not sufficient to achieve the desired direction .   However, the style applied by CSS is not permanent. It can be disabled, ignored, unrecognized, or changed / replaced in different contexts.   Pictures [..]
  Try not to simply connect the CSS style to the general element to achieve the effect.
HTML or XHTML rendered as text / html
  Use markup only. The CSS2 recommendations indicate the use of markup for bidi HTML texts. One can actually say that HTML conforming user agents can bypass CSS bidi properties. Because the HTML specification clearly defines the expected behavior of user agents in relation to bidi tagging.

Note:

Note that the Unicode specification already assigns a direction to the characters and defines the Bidirectionality Algorithm (BIDI) for determining the most appropriate text direction.

However, it is required that the dir attribute be used in HTML. In addition, W3C specifies that dir should not be inferred from the language ( lang ).

HTML 4.01:

If you are using the pre-HTML version 5 version, you will have to specify the LTR or RTL values for the dir attribute.

( See HTML 4.01 specification 8.2 .)

HTML 5:

From HTML 5, you can also use the auto value. The direction will be defined according to the first character "strongly typed", that is, belonging to an alphabet - quotes, commas, numbers, and the like do not count.

Given the low complexity of this algorithm (unlike BIDI), only use this value when the address is not previously known as internationalized dynamic content. A h1 containing content coming from the database, for example. It is almost certain that there will be problems if you use the tags html or body - to set the direction of an entire document.

( See HTML Specification 3.2.5.6 5 ).

    
09.11.2014 / 04:46