11/1/2024, Milan Ugrin
To optimize image display on the web, it’s essential to include width and height attributes directly in the HTML. These attributes not only enhance the user experience but also have a positive impact on page performance and SEO.
For best results, it’s recommended to specify the exact dimensions in which the image will be displayed. However, due to responsiveness, it’s often not possible to set fixed values, so the actual image dimensions are usually taken directly from the CMS. Only numbers are specified, without units (px).
Example:
<img src="example.webp" width="600" height="400">
To achieve responsive design, it is essential to combine HTML attributes with CSS styles. This is ensured by predefined styles provided by libraries such as Bootstrap or Tailwind CSS:
.img-fluid {
max-width: 100%;
height: auto;
}
img {
max-width: 100%;
height: auto;
}
However, we recommend setting the property width: auto; for all images.
If CSS sets different dimensions than the HTML width and height attributes, you don’t need to worry. CSS takes precedence when rendering the image, meaning the final size will be determined by the CSS styles. However, the HTML attributes still matter – they satisfy search engines, and users will experience smoother page loading, specifically the absence of annoying content jumping during image loading.
Modern browsers (except for Safari, which is the rightful successor to Internet Explorer 🤦♂️) can use the width
and height
attributes as an aspect ratio, meaning you don’t have to worry about images overflowing on mobile devices. Responsiveness is, of course, a standard on all our websites.
By filling in the width
and height
attributes, we gain extra points with search engines.
Using the width
and height
attributes for images is crucial for improving page performance, user experience, and SEO. Properly filling in these attributes not only ensures better page rendering but also contributes to accessibility and responsive design. Don’t underestimate the importance of these attributes, and always include them for all images on all websites. Or save yourself the hassle and let us create the website for you. 😉
Contact us, we look forward to meeting you in person or over a call.