3.7. <p> Element

The <p> element defines a paragraph of text. Besides text, things such as anchor links and images can be included in the <p> element. WAP browsers always render a paragraph on a new line.

The <p> element supports two attributes: align and mode. The align attribute is used to change the horizontal alignment of a paragraph. The values left, center and right are supported. The following WML example illustrates how to align a paragraph centrally using the align attribute:


(paragraphEg1.wml)

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>
  <card id="card1" title="WML Tutorial">
    <p align="center">Hello world. Welcome to our WML tutorial.</p>
  </card>
</wml>



Sony Ericsson T610


Sony Ericsson T68i


Nokia Mobile Browser 4.0


The mode attribute is used to set the text-wrapping mode. Two values, wrap and nowrap, are supported. If wrap is specified to the mode attribute, text longer than the screen width will be broken apart and displayed on multiple lines. If nowrap is specified to the mode attribute, the text of the paragraph will be displayed on a single line and how a long line is displayed depends on the WAP browser used. For example:

The following WML example illustrates the effect of the "nowrap" and "wrap" mode on some mobile phone browsers:


(paragraphEg2.wml)

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>
  <card id="card1" title="WML Tutorial">
    <p mode="nowrap">Hello world. Welcome to our WML tutorial.</p>
    <p mode="wrap">You can learn how to build your own WML site in this tutorial.</p>
  </card>
</wml>






Sony Ericsson T610








Sony Ericsson T68i





Nokia Mobile Browser 4.0


Note that if a paragraph's mode attribute is not specified and it is not the first paragraph of the current card, the text-wrapping mode of the previous paragraph will be applied to it. For example, if we change the markup of the previous WML example to the lines below, both paragraphs in the card will be displayed with the "nowrap" mode.


...
  <card id="card1" title="WML Tutorial">
    <p mode="nowrap">Hello world. Welcome to our WML tutorial.</p>
    <p>You can learn how to build your own WML site in this tutorial.</p>
  </card>
...


XML is a stricter markup language than HTML. As WML documents are XML documents, the syntax rules of WML are stricter than HTML. For example, tags and attributes in WML are case-sensitive and they must be in lowercase, while those in HTML are case-insensitive. Thus, the following markup code is invalid in WML but not in HTML:


<P>WML tutorial paragraph 1</P>
<p>WML tutorial paragraph 2</P>
<p ALIGN="right">WML tutorial paragraph 3</P>


This is the correct version of the above markup code in WML:


<p>WML tutorial paragraph 1</p>
<p>WML tutorial paragraph 2</p>
<p align="right">WML tutorial paragraph 3</p>


Another example is that you must close all tags in WML, while you can omit some end tags in HTML. For example, the following markup code is invalid in WML but not in HTML:


<p>WML tutorial paragraph 1
<p>WML tutorial paragraph 2
<p>WML tutorial paragraph 3


The above markup code becomes valid in both HTML and WML if you close all the <p> tags properly, like this:


<p>WML tutorial paragraph 1</p>
<p>WML tutorial paragraph 2</p>
<p>WML tutorial paragraph 3</p>


Some tags do not have any content to be enclosed, so they do not come in pairs. One example is the <br> tag, which is used to tell a browser to start a new line. To close such tags, put a "/" before ">", like <br/>. You need to use <br/> instead of <br> in WML.

Web browsers are more tolerant towards invalid markup than WML browsers. If a HTML page contains markup that does not conform to the specification, a web browser will still try to understand the HTML page and display it as best as it can. WML browsers will not do this. If a WML document contains invalid markup, the WML browser will output an error message directly.


Previous Page Page 6 of 50 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page