Advertisement
Home Open Editor ❯

HTML width Attribute

Example

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

Try this code ❯

Meaning

The width attribute specifies the width of an element.


Standard Syntax

<element width="pixels">


Applies to:

The width attribute can be used on the following element:


Advertisement

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>

Try this code ❯


<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">

Try this code ❯


<iframe> Tag Example

Example

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

Try this code ❯


<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>

Try this code ❯


<object> Tag Example

Example

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

Try this code ❯


<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>

Try this code ❯

Home Open Editor ❯
Advertisement