JavaScript Element clientTop Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance property

What You’ll Learn

Element.clientTop is a read-only instance property that returns the width of an element’s top border in pixels. Learn how it matches border-top-width, how it relates to offsetTop, and how it pairs with clientLeft—with five examples and try-it labs.

01

Kind

Instance property

02

Access

Read-only

03

Type

Integer (px)

04

Measures

Top border

05

Equals

border-top-width

06

Status

Baseline widely

Introduction

The client area is the padded content box inside the borders. clientTop tells you how thick the top border is—the gap from the outer top of the border box to where the padding/content starts.

MDN puts it simply: clientTop is always equal to the computed border-top-width, rounded to an integer. If that width is zero, so is clientTop.

JavaScript
const el = document.getElementById("contained");
console.log(el.clientTop); // e.g. 24 for border-top: 24px
💡
Beginner tip

Remember: clientTop = top border width. It is not margin and not padding.

Understanding the Property

MDN: the clientTop read-only property of the Element interface returns the width of the top border of an element in pixels.

All that lies between offsetTop and the start of the client area is the element’s top border. offsetTop marks the top of the border (not the margin), while the client area begins immediately below the border (including padding). That distance is clientTop.

  • Read-only — change CSS borders, then read again.
  • Integer pixels — top border thickness.
  • Matches CSS — equals border-top-width (rounded).
  • Baseline — widely available since July 2015 (MDN).

📝 Syntax

JavaScript
clientTop

Value

An integer: the top border width in pixels.

ItemDetail
Typenumber (integer pixels)
AccessRead-only
IncludesTop border width
Equalsborder-top-width (rounded to integer)
⚠️
Zero border

If the computed border-top-width is 0, then clientTop is also 0. Prefer a block-level box when you want a clear measurement for teaching or layout math.

📋 MDN Border Example Shape

MDN uses a box with a 24px black top border. The white client area starts after that border, so clientTop is 24:

JavaScript
#contained {
  margin: 1rem;
  border-top: 24px black solid;
  padding: 0px 28px;
  overflow: auto;
  background-color: white;
}
JavaScript
const el = document.getElementById("contained");
console.log(el.clientTop); // 24

Related learning: clientLeft, clientHeight, clientWidth, and getBoundingClientRect().

⚡ Quick Reference

GoalCode / note
Read top borderel.clientTop
Left borderel.clientLeft
Inner sizeel.clientWidth / el.clientHeight
CSS matchborder-top-width (rounded)
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.clientTop.

Kind
get only

Instance

Type
integer

Pixels

Measures
border

Top side

Baseline
widely

Jul 2015+

Examples Gallery

Examples follow MDN Element: clientTop. Labs use a block box with a thick top border so the value is easy to predict.

📚 Getting Started

Read a 24px top border and confirm it matches CSS.

Example 1 — Read clientTop

MDN shape: a box with border-top: 24px.

JavaScript
const el = document.getElementById("contained");
console.log(el.clientTop); // 24
Try It Yourself

How It Works

The top border width becomes the clientTop value. Padding below that border does not change it.

Example 2 — Matches border-top-width

Compare the DOM value with the computed CSS border width.

JavaScript
const el = document.getElementById("box");
const cssTop = parseFloat(getComputedStyle(el).borderTopWidth);
console.log({
  clientTop: el.clientTop,
  borderTopWidth: cssTop
});
Try It Yourself

How It Works

MDN’s rule of thumb: clientTop equals border-top-width rounded to an integer—handy when you already trust computed styles.

📈 Zero Border, Pairing & Snapshot

See zero borders, then pair with clientLeft.

Example 3 — Zero When There Is No Top Border

No top border means clientTop is 0, even with padding.

JavaScript
const el = document.getElementById("box");
// border-top: 0; padding-top: 40px
console.log(el.clientTop); // 0
Try It Yourself

How It Works

Padding sits inside the client area. It does not create a clientTop value.

Example 4 — Pair With clientLeft

Read both border offsets together.

JavaScript
const el = document.getElementById("box");
console.log({
  clientTop: el.clientTop,
  clientLeft: el.clientLeft,
  clientWidth: el.clientWidth,
  clientHeight: el.clientHeight
});
Try It Yourself

How It Works

Together, these properties describe the client rectangle relative to the border box.

Example 5 — Support Snapshot

Feature-detect and remember the measurement rules.

JavaScript
console.log({
  supported: "clientTop" in Element.prototype,
  measures: "top border width (px)",
  tip: "Equals border-top-width (rounded); padding is excluded",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Use clientTop when you specifically need the top border thickness from layout.

🚀 Common Use Cases

  • Measuring thick header/accent borders for custom layout math.
  • Converting between border-box and client-area coordinates.
  • Debugging unexpected vertical offsets when top borders change.
  • Pairing with clientLeft for 2D border thickness.
  • Teaching how offsetTop relates to the client area.

🔧 How It Works

1

CSS defines the top border

border-top-width is part of the box model.

CSS
2

Layout builds the client area

Padding and content sit inside the borders.

Layout
3

clientTop reads the top border

Rounded integer equal to border-top-width.

Measure
4

You get an integer

Use it for offsets, debugging, and box-model teaching.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available).
  • Read-only — change border-top to change the value.
  • Equals border-top-width, rounded to an integer.
  • Related: clientLeft, clientWidth, EventTarget, JavaScript hub.

Browser Support

Element.clientTop is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.clientTop

Read-only integer — width of the top border in pixels (equals border-top-width).

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer Supported
Yes
clientTop Baseline

Bottom line: Use clientTop for top border thickness. It matches border-top-width (rounded). Pair with clientLeft for left border width.

Conclusion

clientTop is a simple border measurement: the top border width in pixels. It matches border-top-width, sits between offsetTop and the client area, and pairs cleanly with clientLeft.

Continue with clientWidth, clientLeft, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use it to read top border thickness
  • Measure block / inline-block boxes
  • Pair with clientLeft for 2D borders
  • Re-read after CSS border changes
  • Compare with border-top-width when debugging

❌ Don’t

  • Expect padding or margin to be included
  • Confuse it with offsetTop (position)
  • Assign to clientTop (read-only)
  • Forget borders can be asymmetric
  • Assume fractional CSS widths stay fractional

Key Takeaways

Knowledge Unlocked

Five things to remember about clientTop

Read-only top border width in pixels—matches border-top-width.

5
Core concepts
📝 02

Integer px

top border

Type
🔍 03

Box offsets

layout math

Use
04

Baseline

widely available

Status
🎯 05

CSS match

border-top-width

Tip

❓ Frequently Asked Questions

It returns the width of the element's top border in pixels. MDN notes it is always equal to border-top-width, rounded to an integer.
No. MDN marks Element.clientTop as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It is a read-only instance property. Change the border with CSS, then read clientTop again.
offsetTop points at the top of the border box (not the margin). The client area starts just below the border, so the gap between them is the top border—clientTop.
When the computed border-top-width is zero. Prefer measuring on block-level boxes when teaching the box model.
clientTop is the top border width; clientLeft is the left border width. Together they describe the client area's border offset.
Did you know?

In MDN’s demo, the yellow area is margin and the white area is the client box. clientTop is the black top border between them—24px in that example.

Next: clientWidth

Learn how to read an element’s inner width in pixels.

clientWidth →

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.

5 people found this page helpful