Javatpoint Logo
Javatpoint Logo

CSS Background-Position Property

Introduction

In CSS, we can use the background-position property to specify the position of the background image. We can set the position of the image at a particular position. The position we have provided is related to the position layer of the background image.

Syntax:

We can implement the background property with the help of the below syntax.

NOTE: The CSS sets the default value for the background-position in the top-left corner of an element, which is repeated both horizontally & vertically.

Properties Value

  • Background-position: left top:

With the help of this property, we can set the image at the top left position of the webpage.

  • Background-position: left center:

With the help of this property, we can set the image at the centre-left position of the webpage.

  • background-position: left bottom:

With the help of this property, we can set the image at the bottom left position of the webpage.

  • background-position: center top:

With the help of this property, we can set the image at the centre-top position of the webpage.

  • background-position: center center:

With the help of this property, we can set the image at the centre position of the webpage.

  • background-position: center bottom:

With the help of this property, we can set the image at the centre bottom position of the webpage.

  • background-position: right top:

With the help of this property, we can set the image at the top right position of the webpage.

  • background-position: right center:

With the help of this property, we can set the image at the centre-right position of the webpage.

  • background-position: right bottom:

With the help of this property, we can set the image at the bottom right position of the webpage.

  • Background-position: 25% 75%:

With the help of this property, we can set the image at 25% from the left and 75% from the top of the webpage.

  • background-position: 30px 80px:

With the help of this property, we can set the image at 30px from the left and 80px from the top..of the webpage.

Example 1:

in the example below, we have created a div at the web page's top left position.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: left top; So that the position of the image is shifted to the top left position of the webpage.

Example 2:

in the below example, we have created a div, which is present at the top centre position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background position: top center; So that the position of the image is shifted to the top center position of the webpage.

Example 3:

in the below example, we have created a div, which is present at the left-centre position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: left centre So that the position of the image is shifted to the left centre position of the webpage.

Example 4:

in the below example, we have created a div, which is present at the left bottom position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: left button; So that the position of the image is shifted to the left bottom position of the webpage.

Example 5:

in the below example, we have created a div that is present at the centre position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: centre centre So that the position of the image is shifted to the centre position of the webpage.

Example 6:

in the below example, we have created a div that is present at the centre bottom position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: centre button; So that the position of the image is shifted to the centre button position of the webpage.

Example 7:

in the below example, we have created a div, which is present at the right top position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: right top So that the position of the image is shifted to the right top position of the webpage.

Example 8:

in the below example, we have created a div, which is present at the top right centre position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background position: top right center; So that the position of the image is shifted to the top right center position of the webpage.

Example 9:

in the below example, we have created a div, which is present at the bottom right position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position: right bottom So that the position of the image is shifted to the right bottom position of the webpage.

Example 10:

in the below example, we have created a div, which is present at the percentage position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background position: centre center; So that the position of the image is shifted to the center center position of the webpage.

Example 11:

in the below example, we have created a div that is present at the pixel position of the web page.

Code:

Output

CSS Background-Position Property

Explanation:

In the above code, we use the background-position in pixel value so that the position of the image is shifted according to the pixel value position of the webpage.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA