CSS Portal

HTML width Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
width
HTML AttributeThis attribute is supported by all modern browsers.
Updated 29th March 2024

Description

The width attribute in HTML specifies the width of an element, such as images, tables, or iframe. When used with an <img> element, it defines the width of the image in pixels or as a percentage of its containing block, allowing for the adjustment of the image's display size without altering the source file. For a <table>, it sets the width of the table itself, again in pixels or as a percentage, influencing how much space the table takes up in the layout. With <iframe>, it determines the width of the framed content area, which can be crucial for embedding external content like videos or other web pages. It's important to note that while the width attribute offers immediate and simple control over element sizing, CSS is often recommended for more flexible and responsive design approaches, as it separates content from styling and provides a wider range of design options.

Syntax

<tagname width="pixels">

Values

  • pixelsA numeric widthin pixels.

Applies To

Example

<img src="images/sunset.jpg" alt="Image description" height="100" width="200">
Open in editor

Browser Support

The following information will show you the current browser support for the HTML width attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee