HTML Academy
The background-repeat Property
Introduction to Backgrounds4/18
Back to the list of tasks
  • 1. The background-color Property
  • 2. The background-image Property
  • 3. The background-repeat Property
  • 4. The background-position Property
  • 5. A Little More on background-position
  • 6. The background-attachment Property
  • 7. The background Property
  • 8. Summary of “Backgrounds: An Introduction. Part 1”
  • 9. Challenge: Cat Comics
  • 10. JPEG format
  • 11. The PNG-8 Format
  • 12. PNG-24 format
  • 13. The GIF Format
  • 14. Multiple backgrounds
  • 15. Effects with a Repeating Background
  • 16. Sprites
  • 17. Summary of “Backgrounds: An Introduction. Part 2”
  • 18. Challenge: CAT Academy
A Little More on background-position
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

The background-position Property

The background-position property controls the position of the background image. The property value consists of two parts separated by a space: x y.

x assigns the horizontal and y the vertical position.

For the x value, you can use the keywords left, center, right, as well as percentage and pixel values.

For the y value, you can use the keywords top, center, bottom, as well as percentage and pixel values.

Here are some examples of how the property is used:

background-position: 50% 50%;
background-position: right bottom;
background-position: 50px 100px;
background-position: 0 100%;
background-position: left bottom;

This is what the examples look like in practice:

  1. The image will be centered;
  2. Bottom right corner;
  3. Padding of 50px from the left and 100px from the top;
  4. Bottom left corner;
  5. Bottom left corner.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>The background-position Property</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="block block1"></div> <div class="block block2"></div> <div class="block block3"></div> <div class="block block4"></div> </body> </html>
CSS
body { padding: 10px; text-align: center; } .block { display: inline-block; width: 192px; height: 192px; margin: 5px; border-radius: 5px; box-shadow: 1px 1px 3px #999999; } .block1 { background-color: #2ecc71; background-image: url("cat_box.png"); background-repeat: no-repeat; } .block2 { background-color: #3498db; background-image: url("cat_fish.png"); background-repeat: no-repeat; } .block3 { background-color: #e74c3c; background-image: url("cat_drunk.png"); background-repeat: no-repeat; } .block4 { background-color: #e67e22; background-image: url("cat_tied.png"); background-repeat: no-repeat; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0

    Assign the following background positions to the blocks:

    1. 50% 50% — To the first block,
    2. 100% 0 — To the second block,
    3. 0 100% — To the third block,
    4. 100% 100% — To the fourth block.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.