Open In App

CSS background-position Property

The background-position property in CSS is mainly used to sets the initial position for the background image ie., it is used to set an image at a certain position. The position that is relative to the positioning layer, can be set by using the background-origin property.

Syntax:



background-position: value;

Note: The background-image is placed default to the top-left corner of an element with a repetition on both horizontally & vertically.

Property values:



Example: This example illustrates the use of background-position property where the position value is set to the left top.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: left top;
    }
    </style>
</head>
  
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the left center.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: left center;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the left bottom position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: left bottom;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the center top position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center top;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the center center position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center center;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the center bottom position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center bottom;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the right top position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: right top;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the right center position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: right center;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set to the right bottom position.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: right bottom;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set in the form of a percentage.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: 25% 75&;
    }
    </style>
</head>
 
</html>

Output:

Example: This example illustrates the use of background-position property where the position value is set in the form of pixels.




<!DOCTYPE html>
<html>
<head>
    <title> CSS | background-position Property </title>
    <style>
    body {
        background-image: url(
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: 30px 80px;
    }
    </style>
</head>
 
</html>

Output:

Supported Browsers: The browser supported by the background-position property are listed below: 


Article Tags :