width Attribute


 

Where to use the width Attribute


Description

On img and object elements

The width attribute may be included on an img or an object element to specify the width of the element, either in pixels or as a percentage of the available horizontal space (usually the parent element's width). This attribute will override the element's natural width and the image/object will be scaled to attain this specified width. If no height attribute is specified, the image/object's natural height will be scaled by the same factor, maintaining aspect ratio.

The advantage of specifying width and height attributes is that it informs the user agent in advance how big the final rendered element will be. The correct space on the screen can be allocated for it, avoiding the need to re-flow the page content once the image/object's actual dimensions have been determined.

See also the height attribute.

On table elements

The width attribute may be included on a table element to specify the desired width of the entire table, either in pixels or as a percentage of the available horizontal space (usually the parent element's width). The W3C, however, encourages authors to use style sheets to specify table widths, rather than the width attribute.

If no width is specified the user agent will determine the width of the table based upon its contents and applicable styling.

On col and colgroup elements

For more information, see the MultiLength attribute type.


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 16 May 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Attribute Index (XHTML 1.1) > width Attribute (XHTML 1.1)