.offset() gets or sets an element’s document-relative coordinates as { top, left } (getter since 1.2; setter since 1.4). It measures the border box — margins are excluded.
Remember
$("p").offset() // { top: Number, left: Number }
$("p").offset({ top: 10, left: 30 })
$("p").offset(function (i, coords) { ... })
.offset() → relative to the document
.position() → relative to the offset parent
Read or write document coordinates with a plain { top, left } object.
Select a visible DOM element.
Call .offset() with no args to read { top, left }.
Pass { top, left } to move the element in the document (jQuery 1.4+).
Use the callback form when each element needs different coordinates.
Piece
Required?
Role
jQuery selection
Yes
Element(s) to measure or move
coordinates / function
Setter only (1.4+)
New { top, left } (or per-element fn)
Return
—
Getter → object; setter → jQuery (chainable)
Pseudocode
Pseudocode
function offset(selection, value):
if value is missing:
el = first matched element
return { top, left } relative to document
for each el in selection:
if value is a function:
coords = value(index, currentOffset)
else:
coords = value
if el.position is static:
set position to relative
move el so border-box = coords
return selection
Reference
Cheat Sheet
Keep these facts handy while reading document position.
Topic
Detail
Syntax
.offset() / .offset({ top, left }) / .offset(fn)
Since
Getter 1.2; setter & callback 1.4
Getter returns
{ top: Number, left: Number }
Relative to
Document (not the offset parent)
Box
Border box (margins excluded)
vs .position()
Document vs offset parent
Static elements
Setter promotes them to relative
Try it
Live Preview
Pick an action and see what .offset() returns or sets on the sample box.
Browser demo of .offset() — same idea as the examples below.
Box
Result
$("#box").offset()
→ { top: …, left: … }
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Get Document Coordinates
Official style: read { top, left } for an element.
Static → relative. If the element was static, jQuery switches it to relative.
Border box. The new position is the border box relative to the document.
Verify. Call .offset() again to confirm the move.
Example 3 — .offset() vs .position()
Same element, two coordinate systems.
jQuery
var $box = $("#box");
var o = $box.offset();
var p = $box.position();
console.log("offset: left " + o.left + ", top " + o.top);
console.log("position: left " + p.left + ", top " + p.top);
One line:.offset() gives document { top, left } — use it for page-level placement, and switch to .position() inside a positioned parent.
Frequently Asked Questions
.offset() with no arguments returns { top, left } for the first matched element relative to the document. .offset({ top, left }) or .offset(function) sets those document coordinates on every matched element and returns the jQuery object for chaining.
.offset() is relative to the document. .position() is relative to the offset parent (usually the nearest positioned ancestor). Use .offset() for page-level placement; use .position() inside a positioned container.
When you set .offset(), jQuery changes static elements to position: relative so top/left can take effect. Prefer setting position yourself if you need long-term CSS control.
The getter has been available since jQuery 1.2. The setter .offset(coordinates) and the callback form arrived in jQuery 1.4.
No. display:none elements are not laid out, so coordinates are unreliable. visibility:hidden can still be measured. Measure while the element is rendered.
No. Values can be fractional on sub-pixel layouts or zoomed pages. Round only when your UI needs integers.