HTML DOM Style backgroundPosition Property

# Style backgroundPosition Property

Style Object

## Example

Change the position of a background-image:

document.body.style.backgroundPosition="top right";
Try it yourself »

## Definition and Usage

The backgroundPosition property sets or returns the position of a background-image within an element.

## Browser Support

The backgroundPosition property is supported in all major browsers.

## Syntax

Return the backgroundPosition property:

object.style.backgroundPosition

Set the backgroundPosition property:

object.style.backgroundPosition=value

## Property Values

Value | Description
--- | ---

top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right

If you only specify one keyword, the other value will be "center".

x% y% | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%.
xpos ypos | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and units
initial | Sets this property to its default value. Read about initial
inherit | Inherits this property from its parent element. Read about inherit

## Technical Details

Default Value: | 0% 0%
Return Value: | A String, representing the position of a background-image
CSS Version | CSS1

## More Examples

## Example

Change the position of the background-image in a <div> element to center bottom:

document.getElementById("myDiv").style.backgroundPosition="center bottom";
Try it yourself »

## Example

Change the position of the background-image in a <div> element to 200px horizontal and 40px vertical:

document.getElementById("myDiv").style.backgroundPosition="200px 40px";
Try it yourself »

## Example

Return the position of the background-image in a <div> element:

document.getElementById("myDiv").style.backgroundPosition;
Try it yourself »

## Related Pages

CSS tutorial: CSS Background

CSS reference: background-image property

CSS reference: background-position property

HTML DOM reference: background property

Style Object

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples