srcdoc
srcdoc attribute
The srcdoc attribute in HTML is utilized with the <iframe> element to define the HTML content to be displayed within the iframe. This feature enables the direct embedding of HTML inside the iframe instead of linking to an external resource.
Syntax
<iframe srcdoc="HTML content"></iframe>
Example
Here’s an example of using the srcdoc attribute:
<h1>The iframe srcdoc attribute</h1>
<iframe srcdoc="<p>Hello world!</p>" src="demo_iframe_srcdoc.htm">
<p>Your browser does not support iframes.</p>
</iframe>
<sandbox> and seamless attributes.Applicable to
The srcdoc attribute can be used with the following element:
| Elements | Attribute |
|---|---|
<iframe> | srcdoc |
Key Points
- Content: The HTML provided in the
srcdocattribute must be valid. - No External Resource Required: In contrast to the
<src>attribute,srcdoclets you embed HTML directly without an external URL. - Browser Compatibility: The
srcdocattribute is supported by most modern browsers, making it a practical choice for embedding static content.
Conclusion
The srcdoc attribute allows embedding HTML directly within an iframe, eliminating the need for an external source. It simplifies content inclusion and is supported by modern browsers. This approach is useful for static content where no external resource is necessary.
src
The src attribute specifies the source of external resources like images, scripts, audio, and video in HTML elements, enhancing multimedia functionality.
srclang
The srclang attribute specifies the language of text tracks within <track> elements, aiding accessibility for users who need subtitles or captions.