Computer >> Computer tutorials >  >> Programming >> CSS

How to create a responsive image with CSS?


Following is the code to create a responsive image with CSS −

Example

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
img {
   width: 100%;
   max-width: 1000px;
}
</style>
</head>
<body>
<h1>Responsive Images Example</h1>
<h2>Resize the window to see responsive image scale up and down</h2>
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940">
</body>
</html>

Output

The above code will produce the following output −

How to create a responsive image with CSS?

On resizing the browser the image will scale down as follows −

How to create a responsive image with CSS?