Object

Struct Object 

Source
pub struct Object;
Expand description

The <object> element - embeds external resource as an object.

§Purpose

The <object> element represents an external resource, which can be treated as an image, nested browsing context, or resource to be handled by a plugin. It provides fallback content for when the object cannot be displayed. More flexible than <embed> with better fallback support, but modern elements like <video>, <audio>, and <iframe> are often more appropriate.

§Content Categories

  • Flow Content
  • Phrasing Content
  • Embedded Content
  • If with usemap attribute: Interactive Content
  • Palpable Content

§Permitted Content Model

  • Zero or more <param> elements
  • Followed by transparent content (fallback)

§Common Use Cases

  • Embedding PDF documents with fallback
  • Displaying SVG images with fallback content
  • Plugin-based content with degradation path
  • Embedding Flash content with alternatives (legacy)
  • Nested browsing contexts with fallback options

§Key Attributes

  • data: URL of the resource
  • type: MIME type of the resource
  • name: Name for form submission or scripting
  • width: Width in CSS pixels
  • height: Height in CSS pixels
  • usemap: Associates with an image map
  • form: Associates with a form element
  • typemustmatch: Type attribute must match resource’s type

§Example

<!-- PDF with fallback link -->
<object data="/documents/report.pdf"
        type="application/pdf"
        width="800"
        height="600">
  <p>Your browser doesn't support PDF viewing.
     <a href="/documents/report.pdf">Download the PDF</a></p>
</object>

<!-- SVG with fallback image -->
<object data="/images/diagram.svg"
        type="image/svg+xml"
        width="400"
        height="300">
  <img src="/images/diagram.png" alt="Diagram">
</object>

<!-- Object with parameters -->
<object data="/media/animation.swf"
        type="application/x-shockwave-flash"
        width="640"
        height="480">
  <param name="quality" value="high">
  <param name="autoplay" value="false">
  <p>Flash content requires the Adobe Flash Player.</p>
</object>

<!-- Nested fallbacks -->
<object data="/video/movie.mp4" type="video/mp4">
  <object data="/video/movie.ogv" type="video/ogg">
    <p>Your browser doesn't support the video. <a href="/video/movie.mp4">Download</a></p>
  </object>
</object>

§Accessibility

  • Provide meaningful fallback content
  • Ensure embedded content is accessible
  • Use aria-label or descriptive fallback text
  • Test with assistive technologies
  • Consider using semantic alternatives when available

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Object

Source§

const TAG: &'static str = "object"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl CanContain<Param> for Object

Source§

impl<T: FlowContent> CanContain<T> for Object

Source§

impl EmbeddedContent for Object

Source§

impl FlowContent for Object

Source§

impl PalpableContent for Object

Source§

impl PhrasingContent for Object

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.