Responsive Image Using CSS

The main priority of today’s websites is that the website should be Responsive. And if you want to align images on those websites, you have to learn how to make images responsive.

There is two way to make an image responsive.

1) Using Bootstrap
2) using CSS

In this article, I’m explaining the concept of responsive images – images that will automatically fit the size of the window screen.

Prerequisites: You should already know the basic concept of HTML,CSS and how to add an image to the website.

Step 1) Add below the HTML

<!DOCTYPE html>
  <title>Responsive Image Using Css</title>
  <div id="myImg">
    <img src="Image.jpg" />

Step 2) Add below the CSS

    /*Responsive image*/
    max-width: 100vh;
    max-height: 100vh;
    /*End responsive image*/
    /*To keep image cnter*/
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    /*End image center*/
    box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px; /*for div shadow*/
     max-width:100%; /*Responsive image*/
     max-height: 100vh; /*Responsive image*/


OutPut :


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories