HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The width attribute specifies the width of the element, in pixels."
The width
attribute specifies the width of the element, in pixels.
width
attribute is used only with
<input type="image">
.
The width
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<canvas> | width |
<embed> | width |
<iframe> | width |
<img> | width |
<input> | width |
<object> | width |
<video> | width |
A <canvas> element with a height and width of 200 pixels:
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
A flash animation with a height and width of 200 pixels:
<embed src="helloworld.swf" width="200" height="200">
An <iframe> with a specified height and width of 200 pixels:
<iframe src="/default" width="200" height="200"></iframe>
An image with a height and a width of 42 pixels:
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
Define an image as the submit button, with height and width attributes:
<form action="/action_page">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
A flash animation with a height and width of 400 pixels::
<object data="helloworld.swf" width="400" height="400"></object>
A video player with a specified width and height:
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
The width
attribute has the following browser support for each element:
Element | |||||
---|---|---|---|---|---|
canvas | 4.0 | 9.0 | 2.0 | 3.1 | 9.0 |
embed | Yes | Yes | Yes | Yes | Yes |
iframe | Yes | Yes | Yes | Yes | Yes |
img | Yes | Yes | Yes | Yes | Yes |
input | 1.0 | Yes | 16.0 | Yes | 1.0 |
object | Yes | Yes | Yes | Yes | Yes |
width | Yes | Yes | Yes | Yes | Yes |