PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By

This is how you make images Responsive in CSS

This is how you make images Responsive in CSS

Hello Folks 👋

What's up friends, this is SnowBit back here. I am a young passionate and self-taught frontend web developer and have an intention to become a successful developer.

Today, I am here with a cool CSS trick that can help and save you from getting it into trouble.

Let's go...

It is very important for a web developer to make mobile responsive images and fit all the content properly in the viewport.

Let's choose an image from Unsplash - (any of your choice) img

Now, it's time to add the image to our HTML file

<img src="https://images.unsplash.com/photo-1644868731706-bdb6485f4274?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=930&q=80" class="img"/>

Now let's get a sneak peek of output,

I guess you have tried to resize the image, haven't you? here, you can notice the image is not responsive and it becomes uncomfortable 😱 to see it on mobile phones.

Now, let's bring our super-power 🔥 of CSS and give it a gracious look.

  width: 100%;
  max-width: 400px;
  height: auto;

Here we are giving the 100% width and independent height to the image, and here max-width property is completely optional

Here's the final output,


Whitespace is never white.

Thank you for reading, have a nice day! Your appreciation is my motivation 😊 - Give it a like

Happy Coding!

Comments (0)

loading comments