Favorites

element() CSS Function

element()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 21st November 2026

The element() function creates a live image from an HTML element on the page, usable as a background. It is only supported in Firefox.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The element() CSS function creates an image from a live HTML element on the page. Whatever the referenced element currently looks like, including its text, images, animations and form controls, is drawn as an <image> that can be used anywhere an image is accepted, such as background-image. If the original element changes, the image updates with it.

The argument is an element ID selector, such as element(#chart). The referenced element does not have to be visible; it can be hidden or placed off-screen, which makes element() useful for reflections, live thumbnails, magnifiers and decorative backgrounds built from HTML content, including a canvas that is being drawn by a script.

element() is only supported in Firefox, and only with the vendor prefix, as -moz-element(). No other browser supports it, so it should only be used as an enhancement with a fallback background.

/* A live reflection of a heading */
.reflection {
  height: 60px;
  background: #e2e8f0;                    /* fallback */
  background: -moz-element(#title) no-repeat;
  transform: scaleY(-1);
  opacity: 0.3;
}

/* Use an animated canvas as a background */
.panel {
  background-image: -moz-element(#animated-canvas);
}

Syntax

element() = element( <id-selector> )

/* supported form */
-moz-element( <id-selector> )

Values

  • <id-selector>An ID selector, such as #source, identifying the element to use as an image. The image updates live whenever that element changes.

Example

<div class="wrap">
<h1>CSS element() examples</h1>
<div class="card">
<span class="source" id="source">Live element</span>
<div class="copy"></div>
<div class="label">background: -moz-element(#source)</div>
</div>
<div class="status"></div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* element() examples */
.source {
display: inline-block;
padding: 10px 16px;
border-radius: 8px;
background: linear-gradient(90deg, #2563eb, #7c3aed);
color: #fff;
font-size: 22px;
font-weight: 800;
animation: hue 4s linear infinite;
}

@keyframes hue {
to { filter: hue-rotate(360deg); }
}

.copy {
height: 80px;
margin-top: 12px;
border-radius: 8px;
background: #e2e8f0; /* fallback */
background: -moz-element(#source) center / contain no-repeat, #e2e8f0;
}

.status {
margin-top: 14px;
padding: 10px 14px;
border-radius: 8px;
background: #fef3c7;
font-size: 13px;
}

.status::after { content: "element() is not supported in this browser (Firefox only)."; }

@supports (background: -moz-element(#source)) {
.status { background: #dcfce7; }
.status::after { content: "-moz-element() is supported: the lower box is a live copy of the badge."; }
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS element() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.