The Wayback Machine - http://web.archive.org/web/20221111170202/https://www.geeksforgeeks.org/css-element-function/
Skip to content
Related Articles

Related Articles

CSS element() Function

Improve Article
Save Article
  • Last Updated : 16 Jul, 2020
Improve Article
Save Article

The element() function of CSS is used to place the image in one tag from the another element present in the page. The image shows changes as the changes are made in another HTML element.

Syntax:

element(id)

Parameters: This function takes the id of the HTML element.

Note: This function does not work with class tag and please run the code in Firefox.

Example:




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, 
                 initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  *{
    color: #fff;
    font-size: 20px;
  }
  .container{
    padding:10px;
    width:fit-content; 
    height:auto; 
    background:-moz-element(#bg1);
  }
  #bg1{
    text-align: center;
    width:fit-content; 
    height:300px; 
    background-image:url(
  }
</style>
<body>
  <div class="container">
    Text from container
  </div>
    
  <div style="overflow:hidden; height:0;
              width:fit-content;">
    <div id="bg1">Text from bg1</div>
  </div>
</body>
</html>

Output:

Image

Browsers supported:

  • Mozilla firefox
  • Firefox for android

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!