SolutionsTools & SDKSupportForums Register



Quick Links
 
XHTML-MP Style Guide Chapter 4 - Text-flow
 
 
The main purpose of a Web or wireless application is to show information to users. For this reason, text is important. Text in the body of your HTML page will show up on the screen of your users:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"  
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">  
<head>
    <title>Plain Text</title>
</head>
<body>
<p>
The time has come for all men of good will
to figure out what XHTML MP is all about<br/>
<br/>
<div style="text-align:right"><i>Openwave</i></div>
</p>
</body>
</html> 



Image 1: Plain text

Of course, you don't have much space to squander on a mobile device screen, so you must make sure that your prose is short and to the point.

Letting text flow uninterrupted on the screen is not always the best way to present information. In most cases you will want to give your document some structure to make the information simpler for the user to interpret.

The example above shows some basic ways to influence the flow of your info: <br/> forces the rendering flow to start from a new line, the 'text-align:right' style attribute forces the Openwave word to squeeze itself against the right border, while <i> is the tag that turns your text into italics.

In the rest of the chapter, we will illustrate the usage of tags that let you control the layout and structure of your XHTML MP documents.

Preformatted text (<pre>) and the `nowrap' extension
The default behavior of plain text on the screen is to collapse all extra white spaces and treat them as a single white space. This default works for most text uses, but when you want to keep the existing text formatting intact, use the <pre> tag:

<body>
<pre>
it's
spring
and
     the
     goat-footed
     
balloonMan    whistles
far
and
wee
</pre>
</body>


will produce:


Image 2: Preformatted text

Another default behavior of browsers is to wrap text to the next line once it reaches the right border. Again, this is acceptable most of the time, however, there may be times when a sentence should be kept intact on one line and viewed by scrolling horizontally. This is particularly useful in the case of Menus (see chapter 3. WML and HDML programmers may recognize horizontal scrolling by its familiar reference: `times-square mode').

Unfortunately, vanilla XHTML MP does not give you the ability to express "times-square mode," so a small extension was introduced in the form of the "mode='nowrap'" attribute for the <p> tag, consistent with WML.code
<p mode="nowrap">
Sure, this sentence is long, but for some reason I don't want it to wrap!
</p>



Image 3: Non-wrapping text

The Openwave browser will let you use mode= "nowrap" on every block element, but doing so is not recommended.

Headers
To organize a document hierarchically you can write headers with different levels.


  <h1>Header 1</h1>
  
  <h2>Header 2</h2>

  <h3>Header 3</h3>

  <h4>Header 4</h4>

  <h5>Header 5</h5>

  <h6>Header 6</h6>


Image 4: Header Tag

It is very important to note that while the Openwave Simulator will render each of the header elements (<h1>...<h6>) with a variety of font sizes, real devices will not likely be able to render six different font sizes. Therefore, you should use the <hx> tags with caution and test your applications on the target handsets to ensure that your application renders as you would expect.

Emphasis tags
One way for authors to add meaning to their text is by emphasizing certain words. Historically, emphasis tags were invented with the assumption that each and every web browser would render the text in the way they saw fit. Accepted practice has changed the semantics to <b> meaning bold, <i> and <em> meaning italics and so on.

XHTML MP adds an extra layer of confusion because a wireless browser only deals with the fonts available on the phone. You have no guarantee that a bold, italic or mono-spaced font is available on the device. In short, trying to track the behavior of each and every tag is expensive and mostly pointless. Just refer to Image 5 below for an example of how you can use the most common emphasis tags.

It is important to note that when the emphasis tags are used, the user can understand what your application is trying to communicate even if the tags are not rendered visibly. For a more detailed description of each tag, please refer to the XHTML Mobile profile and CSS Reference available at developer.openwave.com...

<body>
<p>
    Plain text<br/>
    <em>Lots of emphasis</em><br/>
    <i>Some italics</i><br/>
    <b>This should be bold</b><br/>
    <strong>This one bold too</strong><br/>
    <b><i>Bold and italic</i></b><br/>
    <q>Just a  quote</q><br/>
    <kbd>mono-spaced</kbd>
</p>
</body>




Image 5: Examples of the emphasis tags
Note: On the Web, the <em> tag is synonymous with <i>. In the Openwave browser it is rendered as a synonym of <b><i> (bold and italics).

Links (aka <a href=http://somewherenew>)
The most important tag in the history of the Internet is the anchor <a> tag. The common hyperlink is the foundation of navigation for wireless and Web applications alike. The following example is made slightly less banal by juxtaposing the use of CSS for styling (more about CSS later).

<head>
    <title>Links</title>
<style>
 .test {color:#000000} 
</style>
</head>

<body>
<p>
    Plain link:
    <a href="http://developer.openwave.com/dev/xhtml/index.html">
        XHTML Home
        </a>
    <br/>
    
    Same link, black this time:
    <a class="test" href="http://developer.openwave.com/dev/xhtml/index.html">
        Black path to XHTML Home
    </a>
</p>
</body>



Image 6: Links with style

The Color of Links
While CSS and the browser can assign arbitrary colors to links, the actual link control is a widget in the domain of the device OS. This means that certain devices may not honor CSS and display the link in their default preset color like blue or white or possibly black for visited links.

One important implication of the default color is that you should take care when choosing background colors for your pages and table cells. A page that looks good on one phone may become unusable on another phone because the links are either not visible or not obviously links. In addition, some early versions of XHTML browsers from vendors other than Openwave display links on a line of their own.

Lists
Lists (both ordered and unordered) are HTML constructs that are unchanged in XHTML MP. Because of XML "well-formedness," always remember to close each and every list item with </li>. If you are familiar with the `type' attribute from HTML, you may want to consider the CSS syntax that's recommended now to obtain the same result.
<ul>
    <li>Action
    <ol start="3">
        <li>Secret Agent 008</li>
        <li>Desert Storm II</li>
    </ol>
    </li>    
    <li>Casino
    <ol start="9" style="list-style-type: lower-alpha">
        <li>Black Jack</li>
        <li>Roulette</li>
    </ol>
    </li>
</ul>



Image 7: Nested Lists

Tables
Tables come directly from HTML. Nothing is new from a syntax perspective, but support has been improved. Tables cannot be nested, as a result of requirements from XHTML Basic. Nevertheless, complex tables can be constructed, as the following example illustrates. Notice that in the example, the properties of cell border and shading are controlled by CSS (more about CSS later).

 
<table border="2">
<tr>
    <td style="background-color:red;color:white" colspan="2">Colspan 2</td>
    <td>
        Table
    </td>
</tr>
<tr>
    <td>With</td>
    <td>Background</td>
    <td rowspan="2"; style="background-color:blue;color:white" align="center">Row<br/>Span</td>
</tr>
<tr>
    <td>in first</td>
    <td style="background-image:url(soccer.png);color:blue" align="center"></td>
</tr>
</table>



Image 8: Table layout

While the Openwave browser does a good job at rendering complex tables, a word of caution should be offered about other browsers. An initial analysis of XHTML browser from other vendors has exposed the following glitches:

Some browsers actually draw every cell in a table with a thick line. This may not be what you want.

Browsers behave differently in terms of wrapping content when the table's size exceeds the screen size.

Non Openwave browsers may not be able to apply CSS to table cells and their content.

Horizontal Rules
Horizontal rules are simple, but should be used judiciously. While it is possible to specify the thickness of an <hr>, it is advisable to not exceed two pixels in thickness since size on the display is limited.
<p>
<b>Rome 12.03</b>: 700,000 attend
Labor's day concert
<hr/>
<b>London,11.33</b>: WAP usage figures show
that Wireless is increasingly
popular
</p>



Image 9: Horizontal Rule

While not part of XHTML MP, the legacy HTML `size' and `width' attributes are also supported by the Openwave browser.

Cascading Style Sheets (CSS)
The use of Cascading Style Sheets has become commonplace with web programmers, but may be new to those who have only dealt with HDML or WML:

In 1996, many developers realized that adding more tags and attributes to HTML was not a very scalable approach to improve the graphical capabilities of the web. HTML was knows as tag-soup, browsers were diverging and maintaining sites was becoming tedious. Cascading Style Sheets came as a solution.

A CSS file lets you express styling information elegantly and lets you reuse the style across several pages on a site. If you want to know more about CSS for the Web, a good place to start is: www.w3.org/Style/CSS/. In addition, the XHTML and CSS Reference guide from developer.openwave.com has an excellent discussion of the power and features of CSS.

WAP 2.0 brings the power of CSS to the wireless world by introducing WCSS, an abridged version of Web CSS for wireless devices. We have leveraged CSS in some of the sample code shown previously in this document, but avoided going into too much detail about it. Our code used CSS in the context of an inline style attribute for clarity. Another, more scalable, approach to using CSS is to place all of the selectors and attributes in a separate CSS file and import this file into your XHTML page. Here is a sample shows you how to import a CSS file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" 
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">  
<head>
    <title>MovieLife</title>
    <link rel="stylesheet" href="style.css" type="text/css"/>
</head>


The <link> element instructs the browser to fetch a file with style information called style.css. To avoid any possible confusion, style.css is a URL to a file on the Internet. It is normally a relative URL. In this specific case, the browser will figure out it needs to look at developer.openwave.com/omdtdocs/toolkit_sample/staticSample/movielife/style.css

Style.css contains the following code:
BODY {color: #006699; font-family: Arial, sans-serif; 
      background-color: #FFFFFF}
TD {font-family: Arial, sans-serif}
.bluetext { color: #006699; }
.blue { color: #000000; background-color: #99CCFF;}



From top to bottom, here is what the style-sheet tells the browser:

Rule 1:
  • The body of the page is bluish (RGB=#006699) text over white background.
  • The font used should be either Arial or sans-serif.
    Since each device is responsible for drawing text characters, the decision to support multiple font types, sizes and faces is up to the device manufacturer. If the device cannot match the text characteristics as described by markup and style rules to a supported font, it does a best fit.
Rule 2:
  • The font used inside a table cell should be Arial or sans-serif.
  • Of course, available fonts may be limited as described in the previous rule.
Rule 3:
  • Definition of a style called 'bluetext' which will turn any colorable element (text, link) into blue when applied.
    Note: The links may or may not respect the CSS property defined. This depends on how a phone manufacturer integrates the browser with the software control that implements a link on a specific device. Sharp GX-10 phones, for example, only supports black links. Therefore, it is VERY IMPORTANT to test your code on real devices.
    If you're going to shade backgrounds on a page (or region), don't use black (links would be invisible on some browsers). Similarly, you should not use blue or red (common colors for links and visited links).
Rule 4
  • Define style 'blue' which will turn any colorable element (text, link) into black (#000000) on a bluish background.
    Note:link may or may not respect the CSS property defined for it
Here is how the styles are applied to the different elements of an XHTML MP document:
<table>
<tr class="blue">
    <td>1 <a accesskey="1" href="quick.html">Quick Search</a></td>
</tr>
<tr>
    <td>2 <a accesskey="2" class="bluetext" href="top5.html">Top Five Movies</a></td>
</tr>
<tr class="blue">
    <td>3 <a accesskey="3" href="findmovie.html">Find a Movie</a></td>
</tr>
<tr>
    <td>4 <a accesskey="4" class="bluetext" href="theater.html">Find Theater</a></td>
</tr>
<tr class="blue">
    <td><p mode="nowrap">5 <a accesskey="5" href="theaterlist2.html">Theaters in My Area</a></p></td>
</tr>
<tr>
    <td><a accesskey="6" class="bluetext" href="about.html">6 About MovieLife</a></td>
</tr>
</table>


The result is:


Image 10: CSS applied to an XHTML Page
CSS is by definition very powerful, and the table sample in this chapter is an example of that power in action.

However, there is no guarantee that this would work on all browsers (it probably won't). As a general rule, minimizing the use of CSS is probably wise. If you are very serious about WCSS and want to see the spec, follow this link: http://www.wapforum.org/tech/documents/WAP-277-XHTMLMP-20011029-a.pdf

When should one use CSS?
There are two good reasons to introduce CSS in wireless programming. The first, which we mentioned several times, is convergence with Web programming. The second one is that the introduction of such a powerful framework will make it simple to introduce future extensions to the language while retaining some degree of backwards compatibility. Compatibility is a problem that has plagued wireless development much more than it did on the Web, because of the slowness with which new browsers gain significant market share.

Another advantage of CSS is the fact that external CSS can be cached and re-used across multiple pages. This promotes consistency of look across your application. Having said this, there may be a few reasons to minimize the use of CSS in your applications:

If you are not coding to the Openwave browser exclusively, you may find that other browsers have limited CSS support.


Mobile devices will typically support only a limited amount of fonts (two), which means that you want to use emphasis tags like:
<b>bold<b>
rather than CSS like:
<span style="{font-weight: bold}">bold</span>

The former is shorter, saves bandwidth and will work on all browsers.

If your CSS is a separate file, you gain by having to download the file only once, but you loose in terms of initial end user experience. The browser must download the CSS file, parse it and render the page before it makes sense to the user. This delay is usually not justifiable by the end user.

When a CSS is rendered, the page snaps back to the first line in case the user has already started scrolling. This is another usability glitch you should avoid.

What comes next?
 
Having explored Menus and Text Flow, we will move on to the next core element of XHTML-MP and web programming, Forms.


XHTML-MP Style Guide Chapters
 
XHTML-MP Style Guide Index
1. History of XHTML Mobile Profile
2. XHTML MP in practice
3. Menus in XHTML Mobile profile 1.0
4. Text-flow
5. Forms: Collecting User Data
6. Images and Objects
7. Testing Your Applications
Appendix A
Appendix B


 
 
Copyright © 2000-2008 Openwave Systems Inc.    About Us  |  Openwave  |  Terms & Conditions  |  Privacy Policy  |  Update Profile