Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the direction of HTML <title> tag to right-to-left

Consider this title for a web page:
enter image description here

This is a mixed text from right-to-left and left-to-right languages, and the directionality of the entire text might be:

  1. Left-to-right, if you embed rtl snippets inside ltr text
    enter image description here

  2. Right-to-left, if you embed ltr snippets inside rtl text
    enter image description here

In some web pages, you need to provide a right-to-left title, intermixed with left-to-right text snippets. However, browser doesn't format it correctly. It renders the entire <title> content with ltr directionality. This causes a title, which should be shown like
enter image description here
to be shown like
enter image description here

I know that CSS is not working there. Is there any way to force the browser to render the <title> with correct directionality?

like image 284
Saeed Neamati Avatar asked Jan 02 '12 07:01

Saeed Neamati


People also ask

Which property is used to set the direction of text as right to left?

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?

The main difference between left-to-right (LTR) and right-to-left (RTL) language scripts is the direction in which content is displayed: LTR languages display content from left to right. RTL languages display content from right to left.

Which tag is used to move the content from left to right?

The <marquee> tag in HTML is used to create scrolling text or image in a webpages. It scrolls either from horizontally left to right or right to left, or vertically top to bottom or bottom to top.


3 Answers

You could try using the Unicode RIGHT-TO-LEFT OVERRIDE character. See here.
That is, start the title text with &#x202E;
A quick test shows that it works, at least on my browser; not sure if it will work on all browsers. And it may write pizza backwards. Use with care.

like image 125
Mr Lister Avatar answered Oct 30 '22 02:10

Mr Lister


Use the RIGHT-TO-LEFT EMBEDDING character (RLE, U+202B) at the start of title element contents, e.g.

<title>&#x202b;אבג Hello ابثج</title>

RLE is normally described and used as a character to be used (together with POP DIRECTIONAL FORMATTING) for embedding a run of left-to-right text into right-to-left text or vice versa, in situations that aren’t properly handled by automatic mechanisms. But it seems to work for title elements too, at least on IE, Firefox, and Opera.

like image 31
Jukka K. Korpela Avatar answered Oct 30 '22 02:10

Jukka K. Korpela


Have you tried:

<title>left to right &#x202E;right to left</title>

For the body, you can use CSS (direction: rtl; and unicode-bidi: bidi-override;) or markup (<bdo dir="rtl">).

Demo: http://jsfiddle.net/ThinkingStiff/hD5Sp/

HTML:

<span>left to right <bdo dir="rtl">"right to left"</bdo> left to right</span><br />
<span class="rtl">right to left <span class="ltr">"left to right"</span> right to left</span>

CSS:

.rtl {
    direction: rtl; 
    unicode-bidi: bidi-override;
}

.ltr {
    direction: ltr; 
    unicode-bidi: bidi-override;    
}

Output:

enter image description here

like image 28
ThinkingStiff Avatar answered Oct 30 '22 02:10

ThinkingStiff