Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Applying Background Images to Elements | Adding Decorative Effects with CSS
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
CSS Fundamentals

bookApplying Background Images to Elements

background-image property allows us to add an image as the background of an HTML element. The basic syntax is so simple:

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

As a value for the background-image property, we use url(), and inside these brackets, we specify the image url.

index.html

index.html

index.css

index.css

copy

background-repeat

It determines if the image will be repeated horizontally, vertically, both or not at all.

background-repeat: repeat | repeat-x | repeat-y | no-repeat;
index.html

index.html

index.css

index.css

copy

background-position

background-position is used to set the starting position of a background image within an element's background area. This property allows us to specify where the background image should be placed and how it should be positioned relative to the element. We have to set the position on the x and y axis

background-position: x y
index.html

index.html

index.css

index.css

copy

background-size

Controls how the background image is scaled:

background-size: auto | cover | contain | value in px/em/rem;
  • auto: original image size;
  • cover: fills the entire element, may crop;
  • contain: fits the whole image, may leave empty space;
  • value: custom size (e.g., 100px 50px, 50%).
index.html

index.html

index.css

index.css

copy

1. What does the background-image property do?

2. What does the background-repeat property do?

3. What property determines the position of an element's background image?

question mark

What does the background-image property do?

Select the correct answer

question mark

What does the background-repeat property do?

Select the correct answer

question mark

What property determines the position of an element's background image?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you show me an example of how to use all these background properties together?

What is the difference between `cover` and `contain` for background-size?

How do I center a background image both vertically and horizontally?

bookApplying Background Images to Elements

Swipe to show menu

background-image property allows us to add an image as the background of an HTML element. The basic syntax is so simple:

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

As a value for the background-image property, we use url(), and inside these brackets, we specify the image url.

index.html

index.html

index.css

index.css

copy

background-repeat

It determines if the image will be repeated horizontally, vertically, both or not at all.

background-repeat: repeat | repeat-x | repeat-y | no-repeat;
index.html

index.html

index.css

index.css

copy

background-position

background-position is used to set the starting position of a background image within an element's background area. This property allows us to specify where the background image should be placed and how it should be positioned relative to the element. We have to set the position on the x and y axis

background-position: x y
index.html

index.html

index.css

index.css

copy

background-size

Controls how the background image is scaled:

background-size: auto | cover | contain | value in px/em/rem;
  • auto: original image size;
  • cover: fills the entire element, may crop;
  • contain: fits the whole image, may leave empty space;
  • value: custom size (e.g., 100px 50px, 50%).
index.html

index.html

index.css

index.css

copy

1. What does the background-image property do?

2. What does the background-repeat property do?

3. What property determines the position of an element's background image?

question mark

What does the background-image property do?

Select the correct answer

question mark

What does the background-repeat property do?

Select the correct answer

question mark

What property determines the position of an element's background image?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2
some-alt