css
  1. css-background-image

CSS Background Image

  • The background-image property in CSS specifies an image to use as the background of an element.
  • This can add visual interest and depth to a webpage or app, and can help to reinforce branding or create an appealing atmosphere.

Syntax

background-image: url('image.jpg');

The url() function is used to specify the URL of the image file to use as the background.

Example

body {
    background-image: url('https://static.additionalsheet.com/images//others/llogin.png');
    background-size: cover;
    background-repeat: no-repeat;
    height: 100vh;
    text-align: center
}
Try Playground

In this example, we set the background-image property of the body element to the URL of an image file hosted on a remote server. We also add the background-size and background-repeat properties to control the size and repetition of the image, and set the height of the body element to 100% of the viewport height to fill the screen.

Explanation

The background-image property sets an image as a background of an element and is typically used with HTML elements like body, div, header, footer, etc. The url() property sets the path of the desired image.

The background-size property sets the size of the background image, while the background-repeat property controls how the image is repeated. In this example, we set background-size: cover; to scale the image to cover the entire background, and background-repeat: no-repeat; to prevent the image from repeating.

Use

Using a background image with CSS is a great way to add visual interest and branding to your website or web application. You can use the background-image property in conjunction with other CSS properties to adjust the size, position, and repeat pattern of the image.

Important Points

  • The background-image property requires the url() function to specify the path to the image.
  • The background-size and background-repeat properties can be used to control the size and repetition of the image.

Summary

The background-image property in CSS offers a powerful way to add visual interest and brand identity to your webpages and web applications. With its simple syntax and rich customization options, it provides a versatile tool for developers and designers alike. Try it out on your next project to see what it can do for you!

Published on: