HTML width Attribute

❮ HTML Attributes

Example

<img src="demo/image.jpg" alt="demo" width="300" height="200">

Meaning

The width attribute specifies the width of an element.




Standard Syntax

<element width="pixels">



Browser Support




Status




Applies to:

The width attribute can be used on the following element:

Element Attribute
<canvas> width
<embed> width
<iframe> width
<img> width
<input> width
<object> width
<video> width






Attribute Values

Value Description
pixels Specifies the width of the element.



More Examples

<canvas> Tag Example

<canvas id="myCanvas" width="100" height="100" style="border:1px solid black">
	Your browser does not support the HTML5 canvas tag.
</canvas>

<script type="text/javascript">
	var canvas = document.getElementById("myCanvas");
	var context = canvas.getContext("2d");
	
	context.fillStyle = "red";
	context.fillRect(25,25,50,50);
</script>



<embed> Tag Example

<h1>embed video</h1>
<embed type="video/webm" src="demo/video.mp4" width="300" height="150"><br><br>

<h1>embed image</h1>
<embed type="image/jpeg" src="demo/image.jpg" width="300" height="150">



<iframe> Tag Example

Example

<iframe src="demo/demo.html" height="500" width="400">
	Your browser does not support iframe element.
</iframe>



<input> Tag Example

Example

<form action="action.php">
	<label for="fname">First name:</label>
	<input type="text" id="fname" name="fname"><br><br>
	<label for="lname">Last name:</label>
	<input type="text" id="lname" name="lname"><br><br>
	<input type="image" src="demo/submit.jpg" alt="Submit" width="50" height="50">
</form>



<object> Tag Example

Example

<object data="demo/image.jpg" width="300" height="150"></object>



<video> Tag Example

Example

<video width="340" height="260" controls>
	<source src="demo/video.mp4" type="video/mp4">
	<source src="demo/video.webm" type="video/webm">
	Your browser does not support the video tag.
</video>
❮ HTML Attributes