Many of the elements and attributes used in HTML are now deprecated and are not supported in XHTML. There are some, that although valid in transitional XHTML, are not supported in strict XHTML (see the Appendix). As already expressed in this guide, the use of style sheets (CSS) is the recommended method for the formatting of text and the general layout of a document.
This section covers the equivalent CSS rules for deprecated elements and attributes and those elements and attributes still valid in XHTML along with their equivalent (and recommended) style sheet declarations. The inline version of style sheets is used in the examples below. This is not my recommended method, it just simplifies the examples. See the chapter on style sheets for details of their implementation, use and syntax.
TopTo align text to the left or right margin or to centre it, use the text-align style sheet property.
<p style="text-align: right;"> <h1 style="text-align: center;">
This property can be applied to all block-level elements.
If you want the alignment to apply to a number of headings, paragraphs, text or images, use the <div> block-level element.
<div style="text-align: center;"> <h1>A heading</h1> <p> Some paragraph text .... </p> </div>
The above only describes the simpler methods of aligning text horizontally. However CSS provides us with many more ways in which text can be aligned. CSS has a principle that every element, be it a paragraph, a table cell or a form control is contained within its own box. See the chapter on the "CSS Box Model" in my CSS Reference Guide. That box is made up as follows: there is a content part; this in turn has padding; around the padding is a border; and finally there is a margin.
The padding, border and margin exist for all four edges of this 'box' and all may be formatted, as well as the content part of course. Each component has a range of style properties which may be applied to it. These are covered in details in the chapter on "Margins, Padding & Borders" in my CSS Reference Guide.
TopAll of the formatting and presentational tags available in the strict definition of XHTML tags are described below.
Denotes text as an abbreviation.
The title attribute may be used to specify the long form of the abbreviation.
In some browsers this title text will show when the mouse is over the abbreviation.
This should be used instead of <acronym> when the short form is pronounced letter by letter.
<abbr title="Database 2">DB2</abbr>
Denotes text as an acronym.
The title attribute may be used to specify the long form of the abbreviation.
In some browsers this title text will show when the mouse is over the abbreviation.
This should be used instead of <abbr> when the short form is a pronounable word.
<acronym title="Accredited Environmental General Information System">AEGIS</acronym>
Renders the text as italics (normally - but is browser dependant). Note that line breaks are required to achieve the desired effect.
<address>Xavier Fontainbleau,<br />23 Rue St. Georges,<br /> Chipping Sodbury</address>
Emboldens text.
<b>text</b>is bold
text is bold
Overrides the default text direction.
This requires the 'dir' attribute. Possible values are "ltr" and "rtl" meaning 'left to right' and 'right to left' respectively.
<bdo dir="rtl">This text</bdo>is backwards
This text is backwards
Increases font size.
<big>text</big> is big
text is big
Defines a long quotation, rendering the text indented. It is intended to contain block-level elements not just plain text.
The daffodil thing by Wordsworth: <blockquoute><p>I wandered lonely as a cloud etc...</p></blockquoute>
I wandered lonely as a cloud etc...
Denotes text as a citation or a reference to other sources, rendering it italicised.
Go to <cite>http://www.w3.org</cite>for further information.
Go to http://www.w3.org for further information.
Denotes text as computer code, rendering it as monospaced text.
<code>varB = (varA == 1) ? 1 : 0</code>
varB = (varA == 1) ? 1 : 0
Displays text as deleted.
<del>text</del> is deleted
text is deleted
Denotes the defining instance of a term, normally rendering it italicised.
<dfn>JavaScript</dfn> is a scripting language.
JavaScript is a scripting language.
Indicates emphasised text. This normally displays as italics but depends on the browser.
<em>text</em> is emphasised
text is emphasised
Italicises text.
<i>text</i> is in italics
text is in italics
Defines inserted text. It can be used in conjunction with the <del> element to show modifications.
<ins>text</ins> is inserted
text is inserted
Indicates text to be entered by the user, rendering it as monospaced text.
<kbd>This text is to be entered</kbd>
This text is to be entered
Renders as monospaced text preserving spaces and line breaks.
<pre>
Monospaced text with
spaces
</pre>
Monospaced text with
spaces
Denotes a short inline quotation. It renders the phrase in quotation marks.
It is not supported by all current browsers.
Spike Milligan's gravestone says:
<q>I told you I was ill.</q>
Spike Milligan's gravestone says: I told you I was sick.
Denotes sample output such as from a program or script. It is rendered as monospaced text.
<samp>This Page Is Valid XHTML 1.0 Strict!</samp>
This Page Is Valid XHTML 1.0 Strict!
Reduces font size.
<small>text</small> is small
text is small
Note that in this example the whole text has been made larger in order for the 'small' effect to be more noticeable.
Indicates strong emphasised text. This normally displays as bold but depends on the browser.
<strong>text</strong> is strong
text is strong
Superscripts text.
(x+y)(x+y)=x<sup>2</sup>+y<sup>2</sup>+2xy
(x+y)(x+y)=x2+y2+2xy
Subscripts text.
Water is H<sub>2</sub>O
Water is H2O
Displays as monospaced text.
<tt>Monospaced text</tt>
Monospaced text
Indicates an instance of a variable or program argument, rendering it italicised.
<var>myArray</var>
myArray
WARNING
It should be noted that renderings described above may differ between browsers.
Those elements marked with an * are not supported by Internet Explorer 6.
Two elements that have now been deprecated are the <strike> and the <u> elements.
The CSS property that can achieve the same effect as these is the text-decoration property.
<p style="text-decoration: line-through;">This text is struck through</p>
This text is struck through
<p style="text-decoration: underline;">This text is underlined</p>
This text is underlined
Use underline carefully as underlined text on a web page is usually expected to be a link.
The text-decoration property can also take on the value of "none".
This can be used for removing any underlines from hyperlinks.
Another text formatting property is text-transform.
This is used to change the capitalisation of text.
<p style="text-transform: uppercase;">This text has been changed to uppercase.</p> <p style="text-transform: lowercase;">THIS TEXT HAS BEEN CHANGED TO LOWERCASE.</p> <p style="text-transform: capitalize;">The first letter of each word is capitalised.</p> <p style="text-transform: none;">This text will appear unchanged.</p>
This text has been changed to uppercase.
THIS TEXT HAS BEEN CHANGED TO LOWERCASE.
The first letter of each word is capitalised.
This text will appear unchanged.
Many properties have a value of "none". There may seem little purpose to this when "none" is usually the default. But if a rule has been set up in an external or embedded style sheet for a particular value, an inline style with a value of "none" can be used to nullify the effect.
TopThe <font> element has been deprecated and should be completely replaced by style sheets.
Some of the properties and values available in style sheets are described below.
The name of a specific font e.g. Arial, Verdana. If the font name contains spaces it should be included in single or double quotes.
If the first font name specified cannot be found, the second name will be used and so on. The last name specified should be the generic family name, i.e. serif, sans-serif, monospace, cursive or fantasy.
font-family: 'Times New Roman', Georgia, serif;
This text is Times New Roman.
Values for this property can be specified as an absolute size, relative size, a length or percentage. The usage of percentages and em lengths are recommended.
font-size: 1.5em; font-size: 150%;
This text is 50% larger.
Normal, italic or oblique.
font-style: italic;
This is in italic.
Normal or small-caps.
font-variant: small-caps;
These are small caps. THESE ARE NORMAL CAPS.
Normal or bold.
font-weight: bold;
This is bold text.
This isn't bold text.
This is a shorthand property used to specify a combination of some of the other font properties.
There are added complications with some of these properties so I will only cover a simplified version of this property,
which only encompasses the most common properties font-style, font-weight, font-size and font-family.
Not all values are required, any missing value will be reset to their default value.
If font-family is required it must be preceded by font-size and these two must appear at the end of the list.
font: bold italic 2em 'Comic Sans MS';
This is bold italic twice the normal size using the Comic font.
Each element is considered to be contained within its own box. By using style sheets, an individual element can have its own colour or background image. The different ways of specifying colours in style sheets can be found in my CSS Reference Guide. In the examples below, inline styles have been used for ease of presentation:
The background colour can be set by using the background-color property and the text colour by using the color property.
<p style="background-color: yellow; color:red; ">Here is some red text on a yellow background</p>
Here is some red text on a yellow background
It is recommended that when setting a text color using the color property, the background-color is also set.
This might help circumvent problems caused by browser default colors or the users own style sheets (where the browser supports this!).
An image can be set as a background using the background-image property as follows:
<p style="background-image: (url(../images/star.gif); background-color: #ddd; color: red;
font-size: 2.0em; font-weight: bold">Here is a paragraph with red text on a starry background</p>
Here is a paragraph with red text on a starry background
Once again it is recommended that a suitable background-color property be set.
If for some reason the image cannot be found, the background colour will be used. Also if portions of the image are transparent, the background color fills in the transparent parts.
Depending on the size of the image, it may be tiled so the background is completely filled. A one pixel image will tile itself to fill the whole box. In the example above, the image comprises just the one star but has been replicated to fill the complete space. There are style sheet properties which can prevent replication and position the image in a particular place.
TopMany special characters, such as mathematical symbols and accented characters can be displayed by use of a special numeric or mnemonic (not all cases) code. These codes are called entities. Some examples follow:
Café | is displayed with an acute accent | - | café |
¼ | is displayed as a fraction | - | ¼ |
' | is displayed as an apostrophe | - | ' |
" | is displayed as a quote | - | " |
< | is displayed as a less than sign | - | < |
> | is displayed as a greater than sign | - | > |
Both numeric and mnemonic start with an ampersand and terminate with a semi-colon.
An extensive list can be found at http://www.w3.org/tr/rec-html40/sgml/entities.html.
Top