CSS background-position Property
CSS background-position Property
CSS background-position
property sets the initial position for each background image.
Note: The position is relative to the position layer set by background-origin.
Example
Syntax
Using CSS
Using Javascript
Animatable
Yes, background-position property is animatable. CSS Animatable Properties Reference.
Default Value
Default value for CSS background-position property is 0% 0%.
Property Value
The following table provides a list of values for CSS background-position
property.
Value | Explanation |
---|---|
left top left center left bottom center top center center center bottom right top right center right bottom | Specifies the background-position in text. |
x% y% | Specifies the background-position in percentage. For example, 25% 50%. The first value is the horizontal position and the second value is the vertical. |
xpos ypos | Specifies the background-position in any css length. For example, 25px 100px. The first value is the horizontal position and the second value is the vertical. |
Using Text Value
In the following example, we will use text value for background-position
to center the background image.
Example
Using Percentage Value
In the following example, we will use percentage value for background-position
to set the background image to a desire place.
Example
Using Length Value
In the following example, we will use length value for background-position
to set the background image to a desire place.
Example
Using JavaScript
In the following example, we will demonstrate how to change the CSS background-position
property of an element using JavaScript.
Example
Reminder
Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in CSS.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.