How To Set Height And Width Of An Image In HTML

0
96

To set the height and width of an image in HTML, you can do it in several ways. Here are the most common ones:

 Option 1: Inline with HTML Attributes

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

 Option 2: Using Inline CSS

<img src="image.jpg" style="width: 300px; height: 200px;" alt="Description">

 Option 3: Using a CSS Class

<style>
  .custom-img {
    width: 300px;
    height: 200px;
  }
</style>

<img src="image.jpg" class="custom-img" alt="Description">

Notes:

  • Always include the alt attribute for accessibility and SEO.

  • Use object-fit: cover; in CSS if you want the image to maintain aspect ratio and fill the space.

Need help with making it responsive or maintaining aspect ratio too?

Search
Sellect from all Categories bellow ⇓
Read More
Self Development
How Build a mindset for wealth
Building a mindset for wealth requires...
By flowisetech 2025-02-16 15:40:07 0 455
Self Development
The Role of Emotional Intelligence in Leadership
Emotional intelligence (EI) is a crucial factor...
By flowisetech 2025-03-26 14:17:24 0 634
Social Media
How to Make Money from Facebook – A Step-by-Step Guide
Facebook offers numerous ways to earn money,...
By flowisetech 2025-02-24 08:26:57 0 411
YouTube
How to Create SEO for YouTube
Creating SEO for YouTube involves optimizing...
By flowisetech 2025-02-28 09:38:25 0 434
Social Media
How to Make Money on WhatsApp: A Step-by-Step Guide
Making money from WhatsApp can be highly...
By flowisetech 2025-02-24 08:32:37 0 385