Skip to: content, navigation

by Ian Lloyd

height (HTML attribute)

Spec
Depr. Version
Yes N/A
height="height in pixels"

Example

The height attribute set to "100":

<embed src="giant-grasshopper.jpg" width="300" height="100"></embed>

Description

An embed does not require a height attribute, but it has its uses. The main use for specifying the height (and width) is to improve the experience for a user while a page is loading. If the dimensions are specified in the markup, as the page is loaded the space required for the object is ‘reserved’ by the browser; without this information, the browser does not know how big the object is and cannot allocate the necessary space. On a slow-loading page, the effect can be quite disturbing as content is constantly re-flowed as each new object appears on the page.

The downside of specifying a height (and width) is that if you later decide to update an embedded file that is used site-wide it would require changing all the dimension attributes for each page. Depending on how your web site is managed (manually, template-driven, CMS, server-side includes), this may be a minor niggle or a real issue for you. It is a case of weighing up the pros and cons.

If the height attribute is set by itself, but no width attribute is set, the image will be rescaled proportionally. And depending on the type of content in the embed and the browser rendering it, if non-proportional dimensions are specified (e.g. a 200 x 200 pixel object is set to 100 and 300 pixels in height and width respectively), the results vary (image objects can be stretched/squashed just as they can when applied using the img element, but multimedia objects may not distort in the same way).

Value

A number representing the height of the object in pixels.

Compatibility

The compatibility of this attribute is dependent on the type of object. For image type objects, there is reasonable cross-browser support for the height attribute.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters