The width property specifies the width of an element, and the height property specifies the height of an element.
The width and height of the image can be specified by applying these properties to the IMG element.
img {
width: 200px;
height: 100px;
}
| Property | Value | Explanation |
|---|---|---|
| width | length, %, or auto | the size of the width |
| height | length, %, or auto | the size of the height |
The default is "auto".
The data size of the image doesn't change even if the size is changed by these properties.
Sample image
(width:200px, height:133px)
<html> <head> <title>TAG index</title> <style type="text/css"> #example1 { width: auto; height: auto; } #example2 { width: 300px; } #example3 { width: 150px; } #example4 { width: 100%; height: 133px; } </style> </head> <body> <p><img src="image/photo.jpg" alt="Example" id="example1"> (width:auto, height:auto)</p> <p><img src="image/photo.jpg" alt="Example" id="example2"> (width:300px, height:auto)</p> <p><img src="image/photo.jpg" alt="Example" id="example3"> (width:150px, height:auto)</p> <p><img src="image/photo.jpg" alt="Example" id="example4"> (width:100%, height:133px)</p> </body> </html>
(width:auto, height:auto)
(width:300px, height:auto)
(width:150px, height:auto)
(width:100%, height:133px)