# Background Image

If you’d like to set an image as the background of a web page or an HTML element, rather than simply inserting the image onto the page, then you’ll need to use the CSS **background-image** property.

{% hint style="info" %}
If you want to set an image as the background of the entire web page, then you’d have to apply CSS to the body element.
{% endhint %}

If the image is large enough, it will fill the entire page without the need for additional properties.

![](/files/-MeN4Gb_5JYHASsN4p4J)

```css
background-image: url("https://images.pexels.com/photos/235767/pexels-photo-235767.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
```

If the image is not large enough to cover the entire page, it will repeat.

![](/files/-MeN4GbasCVmufeRmTq5)

**background-repeat: no-repeat** - prevents the image from repeating, but leaves part of the background unfilled.

![](/files/-MeN4GbbRvxzlW-sLd68)

To ensure the image takes up the entire screen, set the **background-size** property to “cover.” To avoid the image stretching out, set the **background-attachment** property to “fixed.” That way, the image will maintain its original proportions.

![](/files/-MeN4GbcC8nh4MtG8PKT)

```css
body {
  background-image: url('mouse.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chnn-anne.gitbook.io/html-css/miscellaneous-topics/background-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
