MDN self-hosted library · e01.org

HTMLImageElement: x property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<img id="avatar" src="/shared-assets/images/examples/grapefruit-slice.jpg" />
<pre id="log"></pre>
css
img {
  margin-left: 30px;
  margin-top: 20px;
  max-width: 4em;
}
js
const logBox = document.querySelector("pre");

const log = (msg) => {
  logBox.innerText += `${msg}\n`;
};

const image = document.getElementById("avatar");

log(`Image's global X: ${image.x}`);
log(`Image's global Y: ${image.y}`);