Chapter 1. Introduction to WML

The heart of WAP from the point of view of you, the content developer, is a new markup language called the Wireless Markup Language (WML). If you have worked with the HyperText Markup Language (HTML), much of WML will look familiar but be warned that there are several differences that can easily catch you out. Some of these differences come from WML’s simplicity compared to HTML: many features that are found in HTML are simply not present in WML.

To use a common example, HTML gives you great control over the appearance of text within a document: you can change its size, specify the typeface to be used, add styling such as boldface or underlining, and have a fine degree of control over its color.

The only controls WML gives you over the text are a few simple styles (emphasis, strong emphasis, boldface, italics, and underlining) and the ability to specify text that is larger or smaller than normal. A further surprise is that most WAP browsers to date don’t even support most of these.

Losing this control over appearance that HTML provides forces you to think in a different way about the pages you write, concentrating on content rather than appearance (substance over style, if you like). If you’ve ever designed a web page to be usable under a really old browser (or a text-only browser) as well as the latest version of a major browser, you’ll already have a good idea of the sort of things you need to bear in mind. Not all browsers even know about recent HTML such features as tables, frames, or stylesheets, and if you want to support people with those browsers, you have three choices: avoid the new feature altogether, write your pages to work even if the feature isn’t present, or provide multiple versions of your pages and allow the user to select his favorite combination of features. In the same way, not all WAP browsers support images, tables, or text style changes,[2] and if you rely on them, you reduce the potential audience for your pages dramatically.

It’s not all bad, though. While WML does drop many of the features of HTML, it adds some powerful new ones, and because it was designed from the start for interactive applications many of the headaches of the web world simply disappear. It also has the advantage of having been designed in one go, rather than having features haphazardly added by different people without any proper overall coordination, which is the case with many of the new features of HTML.

A Complete Example

Before we discuss WML any further, Example 1.1 displays the time-honored “Hello World.” The code for this example, as well as all the other substantial examples, is available on the book’s web page (

Example 1-1. A Simple WML Example

<?xml version="1.0"?>
    "-//WAPFORUM//DTD WML 1.1//EN"

    <card title="First WML Example">
        <p>Hello, World!</p>

Depending on the browser in use, this may look something like Figure 1.1.

Example 1.1 displayed in a WAP browser

Figure 1-1.  Example 1.1 displayed in a WAP browser

Several things need to be explained about this example, but for some of them you’ll have to wait until later chapters. The first thing to note is the special header (the first four lines). This looks confusing, but you don’t actually need to know what it means: just include it at the top of all your WML pages, and all the programs that deal with them will be happy.[3]

The second thing to note is that all tag names are in lowercase (tags are inside angle brackets). This is important: unlike HTML, where <HTML>, <html>, <Html>, and <hTMl> all refer to the same thing, in WML, tag names are case-sensitive. All current WML tag names are lowercase, so you must enter them that way in your pages.

If you’ve seen some HTML, the rest of the WML syntax should look vaguely familiar, although the first tag is <wml>, not <HTML>, and there’s that mysterious-looking <card> tag. The <p> tag simply starts a paragraph of text (in this simple case, there is only the one).

[2] There are several reasons why these features may not be available. One is that some displays may simply be unable to cope with the features. Another reason, which is common at the moment but which will hopefully go away in the future, is that less widely used features were often lost in the rush to get a WAP device out into the market as early as possible.

[3] If you’re familiar with the eXtensible Markup Language (XML), you’ll recognize these lines as the XML prolog for the document. (WML is an XML application, which means that WML documents follow a set of rules laid down in the XML specifications.) If you’re don’t know XML, it doesn’t matter: just copy those four lines and live in blissful ignorance. A number of other parts of WML syntax are also derived from XML: I will point these out as we encounter them.

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.