Open In App

HTML | DOM embed width property

Last Updated : 05 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The DOM embed width property in HTML is used to set or return the value of the width attribute. The width attribute defines the width of the embedded content, in pixels. 

Syntax:

  • Return the width property:
embedObject.width
  • Set the width property:
embedObject.width = pixels

Property Values:

  • px: Specify the width of the embedded content in pixels.

Return value: It returns a number to show the width of embedded content. 

Example: 

HTML
<!DOCTYPE html> 
<html> 

<head> 
	<title>HTML DOM Embed width Property</title> 
</head> 

<body> 
	<center> 
		<h1 style="color:green"> 
			GeeksforGeeks 
		</h1> 

		<embed id="embedID" width="400"
			src="https://www.geeksforgeeks.org/community/"> 
		<br> 
		<button onclick="GFGfun()"> 
			Try it 
		</button> 

		<p id="pid"></p> 

		<script> 
			function GFGfun() { 
				var idwidth = document.getElementById("embedID").width; 
				document.getElementById("pid").innerHTML = idwidth; 
			} 
		</script> 
	</center> 
</body> 

</html> 

Temporary Note on Output : On Run, The output may show a "Refuse to Connect" error due to security restrictions from the GeeksforGeeks site, which prevents embedding. To see the output, replace the src URL with one that allows iframe embedding, such as "https://www.example.com".  

Example: 

HTML
<!DOCTYPE html> 
<html> 

<head> 
	<title>HTML DOM Embed width Property</title> 
</head> 

<body> 
	<center> 
		<h1 style="color:green"> 
			GeeksforGeeks 
		</h1> 

		<embed id="embedID"
			src="https://www.geeksforgeeks.org/community/"> 
		<br> 
		<button onclick="GFGfun()"> 
			Try it 
		</button> 

		<p id="pid"></p> 

		<script> 
			function GFGfun() { 
				var idwidth = 
				document.getElementById("embedID").width=400; 

				document.getElementById("pid").innerHTML
					= idwidth; 
			} 
		</script> 
	</center> 
</body> 

</html> 


Temporary Note on Output : On Run, The output may show a "Refuse to Connect" error due to security restrictions from the GeeksforGeeks site, which prevents embedding. To see the output, replace the src URL with one that allows iframe embedding, such as "https://www.example.com".

Supported Browsers: The browsers supported by DOM embed width property is listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 1 and above
  • Safari 4 and above
  • Opera 12.1 and above
     

Next Article

Similar Reads