<?xml version="1.0" encoding="utf-8"?>
<html lang="en" xml:lang="en"> 
  <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
	 <title>FAQ: CSS vs. markup for bidi support</title>
	 <meta name="keywords" content="i18n internationalisation internationalization localisation localization translation CSS style bidirectional bidi markup"/>
	 <meta name="description" content="W3C I18N FAQ: Should I use CSS or markup to correctly format Unicode-based bidi text in HTML and XML-based markup languages?"/>
	 <link rel="stylesheet" href="/International/style/article-basic.css"/>
	 <link rel="top" title="I18N Activity Home" type="text/html" hreflang="en" href="/International/"/>
	 <link rel="up" title="More resources of this type." type="text/html" hreflang="en" href="___HREF"/>
	 <!-- <link title="___VERSION DESCN IN FOREIGN LANG." type="text/html" rel="alternate" hreflang="___LANG" href="___AND THE HREF" lang="___LANG"
	  xml:lang="___LANG" /> -->
	 <link rel="copyright" href="#copyright"/>
	 <style type="text/css" media="all">
/* <![CDATA[ */
@import "/International/style/article-standards.css";
/* ]]> */
</style> 
  </head> 
  <body bgcolor="white"> 
	 <div id="wai-start" class="hide"> 
		<p>Accesskey n skips to in page navigation. <a href="#contentstart">Skip to the content start</a></p> 
		<p>This document contains examples in another language/script.</p></div> 
	 <div id="site-navigation"> 
		<!--<p class="noprint">&gt; <span title="___LANG_NAME_IN_LANG_OF_CURRENT_PAGE"><a href="___HREF" lang="___LANG" xml:lang="___LANG">___LANG_NAME_IN_FOREIGN</a></span></p>-->
		<a href="/International/"><img id="picture" alt="World map" src="/International/icons/world.gif" width="150" height="61"/></a></div> 
	 <!--<div id="disclaimer"> 
		<p>This document is a translation. In the case of any discrepancy or errors, the <a href="/International/XXX/YYY.en.html">latest English
		  original</a> should be considered authoritative. <a href="#copyright">Original copyright</a> belongs to W3C, as shown below.</p></div>-->
	 <div class="noprint" id="search"> 
		  <form method="get" action="/International/site-search.php" enctype="application/x-www-form-urlencoded" style="margin: 0;"> 
			 <div id="searchSite">I18n site search: <input name="q" type="text" size="15" id="searchField" accesskey="E" maxlength="255"/></div>
			 </form></div><div class="sidebar"> 
		<div class="noprint"> 
		  <h2><a id="links" name="links" tabindex="4">Related links</a></h2> 
		  <p><a href="/International/questions/qa-bidi-controls">FAQ: (X)HTML &amp; bidi formatting codes vs. markup</a></p> 
		  <p><a href="/International/resource-index.html#bidi">Other W3C I18N resources relating to bidirectional text</a></p> </div> </div> 
	 <div id="boilerplate"> 
		<div id="siteicons"><a href="http://www.w3.org/" title="Go to W3C Home Page"><img border="0" src="/Icons/w3c_home.gif" alt="Go to W3C Home Page" width="72" height="48" align="top"/></a><a href="/Architecture/" title="Go to Architecture Domain home page"><img border="0" src="/International/icons/arch.png" alt="Go to Architecture Domain home page" align="top" width="163" height="48"/></a><a href="/International" title="Go to Internationalization Activity Home Page" id="i18n-name"> &#xa0;Internationalization&#xa0;</a></div> 
		<div id="sitelinks" class="noprint"><a href="/International/" title="Internationalization Activity home page.">Home</a>&#xa0;
		  <a href="/International/about" title="About the Internationalization Activity.">About</a>&#xa0;
		  <a href="/International/about#scope" title="Groups that make up the Internationalization Activity.">Groups</a>&#xa0;
		  <a href="/International/resource-index" title="Topic index for information on this site">Topics</a>&#xa0;
		  <a href="/International/technique-index" title="Task-based index of i18n techniques">Techniques</a>&#xa0;
		  <a href="/International/resources" title="Information resources on the Internationalization site.">Resources</a>&#xa0;
		  <a href="/International/log/description" title="Information about news filters and RSS feeds for W3C Internationalization.">News</a>&#xa0;
		  &#xa0;</div> 
		<div id="line">&#xa0;</div></div> 
	 <h1>FAQ: CSS vs. markup for bidi support</h1> 
	 <div id="navigation"> 
		<p><a name="internal-links" id="internal-links">on this page:&#xa0;</a> <a href="#question" accesskey="n" title="Question">question</a>&#xa0;-
		  <a href="#background" title="Background">background</a>&#xa0;-
		  <a href="#answer" title="Answer">answer</a>&#xa0;- <a href="#bytheway" title="By the way...">by the way</a>&#xa0;- <a href="#endlinks" title="Further reading">further reading</a></p> </div> 
	 <div class="section"><a id="contentstart" name="contentstart" tabindex="1"></a> 
		<h2><a id="question" tabindex="1" name="question">Question</a></h2> 
		<div class="section2"> 
		  <p class="question">Should I use CSS or markup to correctly format Unicode-based bidirectional (bidi) text in HTML and XML-based markup languages?</p></div>
		</div> 
	 <p class="background-link noprint" style="text-align: left;"><a href="#answer">[Skip to the answer]</a></p><div class="section"> 
		<h2><a id="background" name="background">Background</a></h2> 
		<p>Text in written in Arabic or Hebrew scripts flows predominantly from right to left (RTL), whereas text in other scripts flows left to right
		  (LTR). Much of the time the Unicode bidi algorithm takes care of the directionality of text, based on the properties of the characters used. However,
		  there needs to be some way of indicating:</p> 
		<ul> 
		  <li> 
			 <p>that the overall orientation of content and layout (such as table cell direction) should be RTL (LTR is the default) because the
				document is mainly written in a script such as Arabic or Hebrew</p></li> 
		  <li> 
			 <p>that part of a LTR document should be treated as RTL, and vice versa</p></li> 
		  <li> 
			 <p>what is the expected flow of text when the <a href="http://www.unicode.org/reports/tr9/">Unicode bidirectional algorithm</a> is insufficient to correctly order adjacent runs of mixed direction
				text</p></li> 
		  <li> 
			 <p>that the inherent directionality provided by the Unicode bidi algorithm should be overridden.</p></li> 
		</ul> 
		<div class="sidenoteGroup"> 
		  <div class="example"> 
			 <div class="box-header">Example:</div> 
			 <p>To clarify the third point above, this sample sentence provides an example of what you may get if you rely solely on the bidirectional
				algorithm. This is incorrect. Because the whole quote is in Hebrew, and therefore runs right to left, the text "W3C" and the comma should appear to
				the left of (ie. after) the Hebrew text. </p> 
			 <blockquote> 
				<p>The title says "פעילות הבינאום, W3C" in Hebrew. &#xa0;&#xa0;<a href="qa-bidi-controls-e1.gif"><img src="img.gif" height="13" width="35" alt="View as an image." title="View as an image."/></a></p></blockquote> 
			 <p>The correct result when displayed would look like this:</p> 
			 <blockquote> 
				<p>The title says "<span dir="rtl">פעילות הבינאום, W3C</span>" in Hebrew. &#xa0;&#xa0;<a href="qa-bidi-controls-e2.gif"><img src="img.gif" height="14" width="35" alt="View as an image." title="View as an image."/></a></p></blockquote></div> 
		  <div class="sidenote">If you are not sure whether your browser or user agent is correctly displaying the Hebrew text in the example, click on
			 the small image buttons to see a bitmap version.</div></div> 
		<p>XHTML/HTML provides markup to fulfill these purposes. These include the following:</p> 
		<table class="inband"> 
		  <tbody> 
			 <tr> 
				<th>Markup</th><th>Effect</th> 
			 </tr> 
			 <tr> 
				<td><code>dir</code> attribute</td><td>Sets the directionality for the element to which it is attached and below. Possible values include
				  <code>rtl</code> and <code>ltr</code>. </td> 
			 </tr> 
			 <tr> 
				<td><code>bdo</code> element</td><td>Overrides the directionality of text as defined by the Unicode bidi algorithm.</td> 
			 </tr> 
		  </tbody> 
		</table> 
		<p>CSS also provides support for text direction as follows:</p> 
		<table class="inband"> 
		  <tbody> 
			 <tr> 
				<th>Property</th><th>Values</th><th>Effect</th> 
			 </tr> 
			 <tr> 
				<td rowspan="2"><code>unicode-bidi</code> </td><td><code>embed</code></td><td>The text to which this is applied will assume the
				  directional flow indicated by the <code>direction</code> property. </td> 
			 </tr> 
			 <tr> 
				<td><code>bidi-override</code></td><td>The text to which this is applied will override the Unicode bidi algorithm according to the
				  directional flow indicated by the <code>direction</code> property. </td> 
			 </tr> 
			 <tr><td rowspan="2"><code>direction</code></td><td><code>ltr</code></td><td>Sets a base direction of LTR for the text to which the
				  <code>unicode-bidi</code> property is applied.</td> 
			 </tr> 
			 <tr><td><code>rtl</code></td><td>Sets a base direction of RTL for the text to which the <code>unicode-bidi</code> property is applied.</td>
				
			 </tr> 
		  </tbody> 
		</table> 
		<p> The question is about whether you should use the markup or the CSS for indicating directionality in XML-based markup languages and HTML.</p> </div><div class="section"> 
		<h2 style="margin-bottom: 0;"><a id="answer" name="answer" tabindex="1">Answer</a></h2> 
		 
		<div class="sidenoteGroup"> 
			 <p>You should always use dedicated bidi markup to describe your content, where available.  CSS may or may not be needed to describe the meaning of that markup. This depends on whether you are dealing with content that is handled by the user-agent as HTML or XML. (Note that <a href="/International/articles/serving-xhtml/#mime">XHTML may be served as either</a>!)  </p> 
			 <div class="sidenote">Always bear in mind that neither markup nor CSS should be used for bidirectional text unless they are needed. Our question relates to
		  situations where the Unicode bidi algorithm is not sufficient on its own, or <code>&amp;lrm;</code> and <code>&amp;rlm;</code> cannot be used to
		  resolve directionality.</div> </div><p></p> 
		<div class="section2"> 
		  <h3><a href="#markup" name="markup" id="markup">Use  dedicated markup</a></h3> 
		  <p>Because directionality is an integral part of the document structure, <strong>markup</strong> 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.</p><p>To produce the desired right-to-left or bidirectional effect, some people simply apply CSS to whatever general paragraph or inline elements surround the relevant text. However, styling applied by CSS is not permanent. It may be turned off, be overridden, go unrecognised, or be changed/replaced in different contexts. Although bidi markup is only needed for the visual rendering of a text it is not purely decorative in
			 function. Markup
			 remains integrated with the document content in a  persistent fashion. It also lends significant clarity to the content if you use dedicated bidi markup.</p> 
		  <p>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.</p> 
		   
		   
		  <p>Note that this presupposes that documents written in markup languages always have recourse to markup specifically dedicated to the support
			 of mixed direction text. People designing a DTD or Schema should be encouraged to add elements or attributes for that purpose.</p> </div><div class="section2"> 
		  <h3><a href="#html" name="html" id="html">HTML or XHTML served as <code>text/html</code></a></h3> 
		  <p>Use <strong>markup</strong> only. The CSS2 recommendation recommends the use of markup for bidi text in HTML. In fact it goes as far as to
			 say that conforming HTML user agents may ignore CSS bidi properties. This is because the HTML specification clearly defines the expected behaviour of
			 user agents with respect to the bidi markup.</p> </div><div class="section2"> 
		  <h3><a href="#xhtml" name="xhtml" id="xhtml">XHTML served as XML, and general XML-based markup languages</a></h3> 
		  <p>XHTML served as <code>application/xhtml+xml</code>, <code>application/xml</code> or <code>text/xml</code> is treated by user agents as XML, not HTML.</p><p>Normally a user agent will not automatically recognize or know what to do with any bidi markup you use in XML documents.
			 <strong>CSS</strong> properties should therefore be used to indicate the expected visual behaviour of text in your document.</p><p>The CSS, however, should always be
			 linked to dedicated bidi markup in the text.</p><p>The following shows the CSS that would be appropriate for the set of markup available in XHTML:</p><div class="example"><p><code>*[dir="ltr"]    { direction: ltr; unicode-bidi: embed }
</code></p><p><code>*[dir="rtl"]    { direction: rtl; unicode-bidi: embed }

</code></p><p><code>bdo[dir="ltr"]  { direction: ltr; unicode-bidi: bidi-override }</code></p><p><code>bdo[dir="rtl"]  { direction: rtl; unicode-bidi: bidi-override }

</code></p></div> </div> 
		 
		 </div> 
	 <div class="section"> 
		<h2><a id="bytheway" name="bytheway">By the way</a></h2> 
		<p>There are situations in XHTML/HTML and possibly other XML-based markup languages where text appears in an attribute or an element that only
		  supports character data. Neither markup nor CSS can be used to modify directionality of either attribute text or <em>part of the text</em> in an element that
		  supports only character data. In these cases you will need to resort to the use of Unicode directional formatting codes. (See the FAQ
		  <a href="/International/questions/qa-bidi-controls.html">(X)HTML &amp; bidi formatting codes vs. markup</a> for more details.)</p> 
		<p>For XML-based markup languages, bidi styling should be defined in a separate style sheet, and that style sheet included in your other style sheets or in your
		  document. This simplifies the development of style sheets and reinforces the difference between bidi and other styling. Think about the bidi
		  style sheet as a part of the schema information that defines the meaning of specific bidi markup, rather than as the decorative styling that can exist
		  in various variants.</p> </div> 
	  
	 <div class="section" id="survey"> 
		<form action="/International/php/survey.php" method="post"> 
		  <fieldset><legend>Tell us what you think</legend> 
			 <p>Was this useful? <br/><span id="scale">Poor
				<input type="radio" name="usefulness" value="1"/><input type="radio" name="usefulness" value="2"/><input type="radio" name="usefulness" value="3"/><input type="radio" name="usefulness" value="4"/><input type="radio" name="usefulness" value="5"/> Excellent</span></p> 
			 <p>I am a:<br/><input name="author" type="checkbox" value="Content author"/> Content author <br/><input name="developer" type="checkbox" value="Developer"/> Developer<br/><input name="designer" type="checkbox" value="Designer"/> Designer<br/><input name="standards" type="checkbox" value="Standards developer"/> Standards developer<br/><input name="other" type="checkbox" value="Other"/> Other</p>
			  
			 <p><input type="hidden" name="docpath" value="/International/questions/"/><input type="hidden" name="docname" value="qa-bidi-css-markup.html"/> </p><p> <input name="comment" type="checkbox" value="Comment"/> I want to add suggestions or comments</p>
			 <p><input type="submit" value="Submit"/></p></fieldset></form></div><div class="section"> 
		<h2><a id="endlinks" name="endlinks">Further reading</a></h2> 
		<ul id="full-links"> 
		  <li> 
			 <p><a href="/TR/html40/struct/dirlang.html#h-8.2">HTML 4 specification, section 8.2, Specifying the direction of text and tables: the dir
				attribute</a> <span class="uri">http://www.w3.org/TR/html40/struct/dirlang.html#h-8.2</span></p></li> 
		  <li> 
			 <p><a href="/TR/REC-CSS2/visuren.html#direction">Cascading Style Sheets, level 2 (CSS2) Specification, section 9.10, Text direction: the
				'direction' and 'unicode-bidi' properties</a> <span class="uri">http://www.w3.org/TR/REC-CSS2/visuren.html#direction</span></p></li> 
		  <li> 
			 <p><a href="/International/questions/qa-bidi-controls">FAQ: (X)HTML &amp; bidi formatting codes vs. markup</a> <span class="uri">/International/questions/qa-bidi-controls</span></p></li> 
		</ul></div> 
	  
	   
	 <div id="author"> 
		<p>Author: Richard Ishida, W3C. <!--Modified by: ___NAME, ___ORGANISATION [Translator: ___NAME, ____ORGANISATION.]--></p></div> 
	 <div class="smallprint"> 
		<div id="logos" class="noprint"><a href="http://validator.w3.org/check/referer"><img src="/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" border="0" title="Valid XHTML 1.0!"/></a><br/><a href="http://jigsaw.w3.org/css-validator/"><img src="/Icons/valid-css" alt="Valid CSS!" height="31" width="88" border="0" title="Valid CSS!"/></a><br/><a href="http://www.unicode.org/"><img border="0" src="/International/icons/UniEncTrans-small.gif" alt="Encoded in UTF-8!" width="84" height="33" title="Encoded in UTF-8!"/></a></div> 
		<p id="version">Content first published 17 July, 2003. Last substantive update 2005-10-21 10:38 GMT. This version
		  <span id="version-info">2005-10-21 10:38</span> GMT</p> 
		<p> For a summary of significant changes, search for <span class="searchkey">qa-bidi-css-markup</span> in the <a href="/International/log/changes">change log</a>.</p> 
		<p class="copyright" lang="en" xml:lang="en"><a rel="Copyright" href="/Consortium/Legal/ipr-notice#Copyright" name="copyright" id="copyright">Copyright</a> © 2005 <a href="/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights
		  Reserved. W3C <a href="/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>, <a rel="Copyright" href="/Consortium/Legal/copyright-documents">document use</a>
		  and <a rel="Copyright" href="/Consortium/Legal/copyright-software">software licensing</a> rules apply. Your interactions with this site are in
		  accordance with our <a href="/Consortium/Legal/privacy-statement#Public">public</a> and <a href="/Consortium/Legal/privacy-statement#Members">Member</a> privacy statements.</p> </div></body> 
</html> 
