The Wayback Machine - https://web.archive.org/web/20240118180028/https://www.geeksforgeeks.org/svg-foreignobject-element/
Open In App
Related Articles

SVG <foreignObject> Element

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas.

The <foreignObject> element of SVG includes elements from a different XML namespace. It is an extensibility point which allows user agents to offer graphical rendering features beyond those which are defined within this specification. 

Syntax:

<foreignObject x = "The x coordinate of the foreignObject"
         y = "The x coordinate of the foreignObject"
         width = "The width of the foreignObject" 
         height = "The height of the foreignObject">
</foreignObject>

    Attributes:

  • x = The x coordinate of the foreignObject.
  • y = The x coordinate of the foreignObject.
  • width = The width of the foreignObject.
  • height = The height of the foreignObject.

Example:




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width,
         initial-scale=1.0">
</head>
  
<body>
    <svg viewBox="500 500 ">
        <style>
            div {
                color: green;
                font: 18px serif;
                height: 100%;
                overflow: auto;
                background-color: black;
            }
        </style>
        <foreignObject x="100" y="25" 
            width="160" height="160">
            <div>
                <br><br>GEEKSFORGEEKS<br><br>
            </div>
        </foreignObject>
    </svg>
</body>
  
</html>


Output:

Supported Browsers:

  • Chrome
  • Edge
  • Opera
  • Internet explorer
  • Safari
  • Firefox

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 31 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials