HTML declare Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The declare attribute was a boolean flag on <object>. In HTML 4 it meant: define this object (with an id) but do not instantiate it until something else referred to that declaration.

Authors paired it with data and type. The HTML Living Standard now lists declare as obsolete: repeat a complete <object> each time you need the resource.

Obsolete — do not use in new pages.

Modern browsers ignore declare. Study it for legacy markup and exams; ship embeds without this attribute.

Not Baseline · Not experimental.

It is a removed historical feature, not a new API. Prefer native media, <iframe>, or a normal <object> with data/type.

HTML Syntax

syntax.html
<object  declare id="name" data="url">…</object>

Boolean form: write declare alone (or historically declare="declare"). Always needed an id so later markup could refer to the declaration.

Attribute Values

Boolean only — no other meaningful values:

ValueDescriptionTry it
declare (present)Historical: declaration only — do not instantiate yetTry it
declare="declare"Same boolean, XHTML-style spellingTry it
Attribute omittedNormal object — load/instantiate as usual (correct for today)Try it
Any other tokenNot useful — treat as boolean presence in old UAs; ignored nowTry it

Live Preview

Toggle declare on a demo <object>. Modern browsers still ignore the flag — this only shows the attribute in the DOM.

Obsolete attribute demo. Expect no change in loading behavior.

object
Fallback text if the object cannot load.

hasAttribute("declare") = true — ignored by modern browsers

HTML Examples

Historical patterns for study, plus a modern replacement. Use Try It Yourself for a live editor.

Example 1 — HTML 4 Style Declaration

Declare with an id, then refer later (historical pattern from HTML 4).

HTML
<!-- Historical only — browsers ignore declare today -->
<object
  declare
  id="earth.declaration"
  data="earth.mpeg"
  type="application/mpeg">
  The <strong>Earth</strong> as seen from space.
</object>

<p>
  <a href="#earth.declaration">View the Earth</a>
</p>
Try It Yourself

How It Works

  1. declare marked the object as a definition only (HTML 4 idea).
  2. id named the declaration so other markup could refer to it.
  3. data / type described the resource (same idea as today).
  4. Today: the flag is ignored — treat this as history, not a pattern to copy.

Example 2 — Boolean Toggle in JavaScript

You can still set or remove the attribute in the DOM; behavior does not change.

HTML
<object id="demo" data="" type="text/plain">Fallback</object>
<button type="button" id="btn">Toggle declare</button>
<p id="out"></p>

<script>
  var obj = document.getElementById("demo");
  var out = document.getElementById("out");

  function show() {
    out.textContent =
      "hasAttribute(\"declare\") = " + obj.hasAttribute("declare");
  }

  document.getElementById("btn").addEventListener("click", function () {
    if (obj.hasAttribute("declare")) {
      obj.removeAttribute("declare");
    } else {
      obj.setAttribute("declare", "");
    }
    show();
  });

  show();
</script>
Try It Yourself

How It Works

  1. setAttribute("declare", "") adds the boolean attribute.
  2. removeAttribute("declare") clears it.
  3. hasAttribute reports presence in the DOM.
  4. No loading change — useful only to inspect obsolete markup.

Example 3 — Modern Replacement

Omit declare. Repeat a full <object> when needed, or use native media with preload.

HTML
<!-- Correct today: no declare — repeat object if reused -->
<object data="poster.pdf" type="application/pdf" width="320" height="200">
  <p>PDF preview unavailable. <a href="poster.pdf">Download the PDF</a>.</p>
</object>

<!-- Or control media loading with video + preload -->
<video controls preload="metadata" width="320">
  <source src="clip.mp4" type="video/mp4">
  Your browser does not support video.
</video>
Try It Yourself

How It Works

  1. Skip declare entirely on new markup.
  2. Need the resource twice? Repeat the full <object> (WHATWG guidance).
  3. For video/audio, use native elements and preload instead of object tricks.
  4. Always provide fallback content inside <object> for accessibility.

Edge Cases & Pitfalls

The main risk is copying HTML 4 object patterns into modern sites.

obsolete

Ignored by current browsers

Adding declare will not delay instantiation. Do not design loading UX around it.

scope

Only ever for <object>

It was never valid on img, video, or iframe. Those elements have their own loading attributes.

legacy

Related obsolete object attrs

classid, codebase, and standby are also obsolete. Prefer data + type.

a11y

Keep fallback content

Put useful HTML inside <object> for agents that cannot show the resource — that advice still applies without declare.

exams

Know it; do not ship it

Interview or certification questions may still mention declaration-only objects. Answer with “obsolete / ignored.”

Browser Support

declare was an HTML attribute on object. It is obsolete in the Living Standard and is not a modern browser feature to rely on.

✓ Obsolete · Ignored

declare

Listed as obsolete for object. Current Chrome, Firefox, Safari, and Edge do not implement declaration-only behavior. Safe conclusion: never depend on it.

0% Useful modern support
Google Chrome Ignored
Obsolete
Mozilla Firefox Ignored
Obsolete
Apple Safari Ignored
Obsolete
Microsoft Edge Ignored
Obsolete
Opera Ignored
Obsolete
Samsung Internet Ignored
Obsolete
Internet Explorer Legacy partial
Legacy only
declare Obsolete / ignored

Bottom line: Do not use declare in production. Repeat object elements or use video/audio/iframe and modern loading attributes instead.

Key Takeaways

  • History: boolean on <object> meaning “declare now, instantiate later.”
  • Status: obsolete in the HTML Living Standard — do not use.
  • Replacement: repeat a full <object>, or use native media / iframe.
  • Loading control: look at preload, defer, and async instead.

One line: declare is a legacy object flag — ignored today; omit it and use modern embeds.

Frequently Asked Questions

In HTML 4, declare on an object meant “define this object but do not instantiate it yet.” Later markup could refer to that declaration by id. Modern browsers ignore the attribute.
No. The HTML Living Standard lists declare on object as obsolete. Authors must not use it. Repeat a full object element whenever you need the resource again.
Only the object element. It was never a global attribute.
Yes. Presence alone turned on declaration-only mode. Values like declare="declare" or declare="true" were historical forms of the same boolean.
For embeds, use a normal object with data and type (or embed/iframe). For media loading, prefer video/audio with preload, or script with defer/async. Do not rely on declare.
No. They treat the object like any other object. Studying declare is useful for reading old docs and exams, not for new pages.

Next: default

Mark the default text track on media with the default attribute.

default tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful