jQuery .position() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is .position()?

.position() returns the current coordinates of the first matched element as { top, left }, relative to the offset parent (since jQuery 1.2). It measures the element’s margin box against the parent’s padding box.

Remember
$("p").position()   // { top: Number, left: Number }

.position()  → relative to the offset parent
.offset()    → relative to the document

// No setter — use .css() or .offset() to move
NeedUse
Coords inside a positioned parent$el.position()
Page / document coords$el.offset()
Move with local coords$el.css({ top, left })

How to Use .position()

Read local coordinates; move with CSS when you need a write.

  1. Select a visible DOM element.
  2. Call .position() to get { top, left } vs the offset parent.
  3. Use those numbers for local layout math (tooltips, neighbors, nudges).
  4. To move the element, set position in CSS and write top/left with .css().
PieceRequired?Role
jQuery selectionYesElement to measure
Arguments—None (getter only)
Return—{ top, left } (or undefined if empty)

Pseudocode

Pseudocode
function position(selection):
    if selection is empty:
        return undefined

    el = first matched element
    parent = offsetParent(el)   // nearest positioned ancestor, or body
    return {
        top:  distance from parent's padding edge to el's margin edge
        left: distance from parent's padding edge to el's margin edge
    }

Cheat Sheet

Keep these facts handy while reading local position.

TopicDetail
Syntax.position()
SincejQuery 1.2
Returns{ top: Number, left: Number }
Relative toOffset parent (not the document)
Setter?No — use .css() or .offset()
vs .offset()Local parent vs document
Hidden elementsNot supported / unreliable

Live Preview

Pick an action and see what .position() returns inside a positioned wrapper.

Browser demo of .position() — same idea as the examples below.

Result
$("#box").position()
→ { top: …, left: … }

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Get Offset-Parent Coordinates

Official style: read { top, left } for an element.

jQuery
var position = $("p").first().position();

console.log("left: " + position.left + ", top: " + position.top);
Try It Yourself

How It Works

  1. Select. Target the first paragraph with $("p").first().
  2. Read. .position() returns a plain object with top and left.
  3. Meaning. Those numbers are distances from the offset parent.
  4. Use. Ideal when placing something near another element in the same container.

Example 2 — .position() vs .offset()

Same element, two coordinate systems.

jQuery
var $box = $("#box");
var p = $box.position();
var o = $box.offset();

console.log("position: left " + p.left + ", top " + p.top);
console.log("offset:   left " + o.left + ", top " + o.top);
Try It Yourself

How It Works

  1. Parent. .position() measures from the offset parent.
  2. Document. .offset() measures from the page origin.
  3. Why both? Nested layout needs parent coords; overlays often need document coords.
  4. Rule. Pick the system that matches where you will place the next element.

Example 3 — Move with .css() (No Setter)

Read .position(), then write top/left yourself.

jQuery
var $box = $("#box");
var p = $box.position();

$box.css({
  position: "relative",
  top: p.top + 20,
  left: p.left + 10
});

var next = $box.position();
console.log("left: " + next.left + ", top: " + next.top);
Try It Yourself

How It Works

  1. Read. Capture the current local coordinates.
  2. Position. Ensure the element can accept top/left (relative or absolute).
  3. Write. Apply new values with .css() — not .position().
  4. Verify. Call .position() again to confirm the nudge.

Example 4 — Offset Parent Changes the Origin

A positioned wrapper becomes the reference for .position().

jQuery
var p = $("#box").position();
console.log("inside wrap → left " + p.left + ", top " + p.top);

console.log("offsetParent tag → " + $("#box").offsetParent()[0].tagName);
Try It Yourself

How It Works

  1. Wrapper. A position:relative ancestor becomes the offset parent.
  2. Local zero. A child at the top-left reports { top: 0, left: 0 }.
  3. Inspect. .offsetParent() shows which element is the origin.
  4. Takeaway. Change the wrapper’s position, and the coordinate system changes with it.

Edge Cases & Pitfalls

Check these before trusting .position() in layout code.

api

No setter overload

.position({ top, left }) does not exist. Use .css() or .offset() to move elements.

hidden

Hidden elements are unsupported

Do not read .position() on display:none elements. Measure while rendered.

coords

Do not confuse with .offset()

Offset-parent coords vs document coords. Mixing them breaks overlays and drag logic.

fraction

Values may be fractional

Sub-pixel layouts can return numbers like 12.5. Round only when your UI needs integers.

Browser Support

.position() has shipped since jQuery 1.2 as a getter-only API. Works in all modern browsers with jQuery loaded.

✓ jQuery 1.2+

.position()

Offset-parent coordinates API — returns { top, left }. No setter; pair with .css() or .offset() to move elements.

100% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.position() Excellent

Bottom line: Use .position() for local layout coordinates. Switch to .offset() when you need document-relative placement.

Performance Notes

ApproachCostBest for
.position()Layout readOffset-parent coordinates
.offset()Layout readDocument coordinates
Repeated reads in a loopCan thrash layoutCache { top, left } first

Coordinate getters force layout. Read once, reuse the object, and avoid calling .position() inside tight animation frames unless needed.

Key Takeaways

  • Role: get { top, left } relative to the offset parent.
  • vs offset: local parent vs document.
  • No setter: move with .css() or .offset().
  • Safety: measure visible elements; expect fractional pixels.

One line: .position() gives offset-parent { top, left } — read for local layout, and write moves with .css() or .offset().

Frequently Asked Questions

.position() returns { top, left } for the first matched element relative to its offset parent — the nearest positioned ancestor (or the body). It is a getter only; there is no .position({ top, left }) setter.
.position() is relative to the offset parent. .offset() is relative to the document. Use .position() for layout inside a positioned container; use .offset() for page-level placement.
Usually the closest ancestor with position relative, absolute, fixed, or sticky. If none qualify, the document body is used. That ancestor is the origin for .position().
Set CSS position (relative or absolute), then use .css({ top, left }) with values from .position() or your own numbers. For document-level moves, use the .offset() setter instead.
No. jQuery does not support reliable readings on display:none or non-rendered elements. Measure while the element is visible.
No. Values can be fractional on sub-pixel layouts or zoomed pages. Round only when your UI needs integers.

Next: .scrollLeft()

Learn how to read and set horizontal scroll position.

.scrollLeft() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful