In HTML, you can use the width
and height
attributes to set the dimensions of an image element. These attributes specify the width and height of the image in pixels, like this:
<img src="example.jpg" width="300" height="200" alt="Example Image">
Alternatively, you can use CSS to style the image element and set its dimensions. To do this, you can use the width
and height
properties in a CSS rule targeting the img
selector, like this:
img {
width: 300px;
height: 200px;
}
Both methods will achieve the same result of setting the width and height of the image element, but using CSS provides more flexibility in terms of styling and layout options.