Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch an image to fill width of browser window

Tags:

html

css

I have an image, and I want the width to fill up the browser window, no matter the size of the window.

How do I do this in HTML and CSS?

like image 368
Billjk Avatar asked Mar 16 '12 02:03

Billjk


People also ask

How do I stretch an image to fit the screen in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels. For example, the original image is 640×960.


2 Answers

You can add a div with width an height of 100%, also set image's width and height are 100%

<div id="wrapper">
    <img src="https://picsum.photos/200/200">
</div>​​​​​​​​​​

CSS:

#wrapper, img{
    width:100%;
    height: 100%;
}

jsfiddle

like image 69
sbagdat Avatar answered Sep 21 '22 08:09

sbagdat


<img src="filename.jpg" alt="alt text" width="100%" />

This assumes that the image's container is as wide as the browser window.

like image 23
Brian Willis Avatar answered Sep 19 '22 08:09

Brian Willis