How To Make Full-Screen Background Image Using CSS
How To Make Full-Screen Background Image Using CSS
In HTML, background images are used to style and enhance the look of the web pages.
How to Apply Hover on Grid Auto
By default, web page images are displayed in the upper left corner of the screen. Flow in Tailwind?
However, you can resize the image in full-screen mode. CSS provides “background-
position” and “background-size” properties that can be used to force an image to display How to Apply Hover on Row Grid in
Tailwind?
on the whole screen.
In the above mention syntax, the following four properties of the background property are
mentioned:
37 47 19 10
How to Set How to Center How to Blur a Darken Background CSS Ba
Background Image i… Background Images… Background Image i… Image CSS Image O
Let’s move to the example in which we will make a full-screen background image using
CSS.
Example
In the HTML, we will create a container and set its class name as “div” and add the
heading using the <h1> tag. Moreover, to place the heading in the center of the page, we
will use the <center> tag.
HTML
<body>
<div class="div">
<center>
<h1>Welcome to LinuxHint</h1>
</center>
</div>
</body>
Then, assign the value of the margin property as “0” and height as “100px” to the whole
body of the HTML.
Replay
CSS
html, body {
margin:0;
height:100%;
}
In the next step, style the created container using “div” and adjust the width and height of
the div as “100px”. We will use border property to add the border around the div with
“25px” width, style as “groove” and color of the border as “rgb(184, 147, 147)”:
div {
width:100%;
height:100%;
border:25px groove rgb(184, 147, 147);
The outcome of the above-mentioned code is given below. You can see that the heading
and border are created:
Note: As you can see, in the above-provided image border from the right and bottom is
hidden, this is because the width and height of the div are already “100%”, so when we
add a border, additional width and height will be added. To avoid this, we will use the
“box-sizing” property of CSS as it allows us to include a border in the element’s width and
height.
To do so, we will set the value of box-sizing as “border-box” to include the border within
the total width and height of the div:
box-sizing:border-box;
The below-given image indicates that the border is successfully placed within the width
and height of the div:
Replay
Now, we will add the background image by using the “background-image” property and
specify the image url in it as “url(image.jpg)”:
div {
background: url("image.jpg");
}
In the below-provided image, you can see that the background image is successfully
added, but it is repetitive:
Replay
To avoid the repetition of the image, the “background-repeat” property is utilized. Here,
we will set the value of background-repeat as “no-repeat”:
div {
background-image: url("image.jpg");
background-repeat:no-repeat;
In the below-provided output, you can see that the repetition of the image is stopped;
however, the image is not displayed on the screen:
To display the image on full-screen, we will utilize the “background-size” property. And
set its value as “cover”, which means the image will cover the whole area of the created
container:
div {
background-image: url("image.jpg");
background-repeat:no-repeat;
background-size:cover;
The below image indicates that the image is displayed on the full screen and is cut off.
This is because the size of the image is greater than the div size:
To fix this problem, use the “background-position” property and set the position of the
image as “center”:
div {
background-image: url("image.jpg");
background-repeat:no-repeat;
background-size:cover;
background-position:center;
That’s it! We have explained the method to make a full-screen background image using
CSS.
Conclusion
To create a full-screen background image using CSS, first, create a div and set the width,
height, and margins to fill the screen. After that, create a border around the div, then add
an image to it using the “background-image” property. To adjust the image according to
the full screen, use the “background-repeat”, “background-size”, and “background-
position” properties. This article has explained the complete method to make the full-
screen background image using CSS.
-30%
Explore More
search text SHOW ALL
37 47 19 10
How to Set How to Center How to Blur a Darken Background CSS Bac
Background Imag… Background… Background Imag… Image CSS Image O
Sharqa Hameed
I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold
masters degree in computer science and am passionate about learning and
teaching.