HTML declare Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 3 Examples
Legacy & Obsolete

Introduction

The declare attribute is an obsolete HTML attribute that was used with the <object> element. It indicated that the object’s properties were declared in the document but the object should not be instantiated (loaded) immediately. Modern browsers do not support this behavior, and you should not use declare in new web projects.

What You’ll Learn

01

Obsolete

Not in HTML5.

02

object Only

Legacy embed.

03

Boolean

Presence = on.

04

Declaration

Not loaded yet.

05

setAttribute

JS toggle.

06

Alternatives

preload, lazy.

Purpose of declare

The original purpose of the declare attribute was to mark an <object> as a declaration only. The browser would know about the object’s properties without loading or running the embedded resource right away. Another object could reference that declaration later. This was intended to help with performance when embedding large plugin-based content in early HTML.

⚠️
Do not use in modern projects

declare is obsolete. No major browser applies declaration-only object behavior today. Use native HTML5 elements and modern loading attributes instead.

📝 Syntax

Historical syntax on an <object> element:

declare.html
<object data="resource.swf" type="application/x-shockwave-flash" declare>

  <p>Fallback content</p>

</object>

Syntax Rules

  • Boolean attribute: presence alone meant declaration-only mode.
  • Applied only to <object>, not to video, img, or script.
  • No meaningful values beyond empty declare or declare="".
  • Obsolete in HTML5 — treat as historical reference only.

💎 Values

Unlike many attributes, declare has no specific string values. It is a boolean attribute:

  • Attribute present — Object is a declaration only (historical behavior).
  • Attribute absent — Object would be instantiated normally (in legacy browsers).
declare-boolean.html
<!-- Declaration only (obsolete) -->

<object data="file.pdf" type="application/pdf" declare></object>



<!-- Normal object (still valid for some embeds) -->

<object data="file.pdf" type="application/pdf"></object>

⚡ Quick Reference

ItemDetailsToday
Element<object> onlyStill valid element
TypeBoolean attributeObsolete
Historical effectDeclare, don’t instantiateIgnored
JS addsetAttribute("declare", "")No practical effect
JS removeremoveAttribute("declare")Safe cleanup
Modern altpreload, loading="lazy"Use these

Applicable Elements

ElementSupported?Notes
<object>Was yes (obsolete)Only element that used declare
<video>, <audio>NoUse preload instead
<img>, <iframe>NoUse loading="lazy"
<script>NoUse defer or async

declare vs modern loading controls

GoalObsolete approachModern approach
Delay video load<object declare><video preload="none">
Lazy imagesNot applicable<img loading="lazy">
Defer scriptsNot applicable<script defer>
Lazy iframesNot applicable<iframe loading="lazy">

Examples Gallery

Historical declare syntax, JavaScript toggle, and a modern preload alternative.

Implementation Example

index.html
<object data="movie.mp4" type="video/mp4" declare>

  <p>Your browser does not support HTML5 video.</p>

</object>
Try It Yourself

How It Works

In this example, declare historically indicated that the object’s properties are declared but should not be immediately loaded. Today it has no practical effect.

Dynamic Values with JavaScript

Since declare is a boolean attribute, it can be added or removed with JavaScript (useful when reading legacy markup or cleaning up old HTML):

dynamic-declare.html
<script>

  // Add declare

  document.getElementById("dynamicObject").setAttribute("declare", "");



  // Remove declare

  document.getElementById("dynamicObject").removeAttribute("declare");

</script>



<object id="dynamicObject" data="movie.mp4" type="video/mp4">

  <p>Fallback content</p>

</object>
Try It Yourself

How It Works

The script adds and removes declare on an object with id dynamicObject. The DOM updates, but loading behavior does not change in modern browsers.

Modern Alternative

Instead of declare, control media loading with native HTML5 attributes:

modern-preload.html
<video controls preload="metadata">

  <source src="movie.mp4" type="video/mp4">

</video>

How It Works

preload="none", metadata, or auto on <video> and <audio> gives you explicit, supported control over when media data is fetched.

♿ Accessibility & UX

  • Prefer native media<video> and <audio> with controls are more accessible than legacy object embeds.
  • Fallback content — Always include meaningful fallback inside <object> when you still use it for PDFs.
  • Performance helps everyone — Lazy loading and sensible preload values reduce data use and improve experience on slow connections.
  • Remove obsolete attrs — Cleaning up declare from legacy HTML simplifies maintenance without changing behavior today.

🧠 How declare Worked (Historically)

1

Author adds declare

Object marked as declaration-only in markup.

Markup
2

Browser registers object

Properties known; resource not instantiated yet.

Legacy
3

Another reference loads it

Referenced object could be instantiated later.

Reference
=

Obsolete today

Use preload, lazy loading, and native HTML5 media instead.

Browser Support

The declare attribute is obsolete. It is not part of modern HTML5 practice and is ignored by current browsers.

⚠️ Obsolete · Not supported

Historical attribute only

Modern browsers do not implement declaration-only object behavior.

0% Practical support
declare attribute Obsolete

Bottom line: Do not use declare in new code. Remove it from legacy markup when you find it.

💡 Best Practices

✅ Do

  • Use video/audio with preload for media loading control
  • Use loading="lazy" on images and iframes
  • Remove declare from legacy HTML during cleanup
  • Prefer native HTML5 elements over object for video
  • Test performance with modern devtools

❌ Don’t

  • Add declare to new object elements
  • Expect declare to delay loading in modern browsers
  • Use object with declare for HTML5 video
  • Rely on plugin-era embedding patterns
  • Confuse declare with defer or preload
  • Since declare is obsolete and not supported by modern browsers, it is not recommended for contemporary web development.
  • Consider modern alternatives such as the preload attribute on <video> and <audio>, or lazy loading techniques.
  • Always test your web pages across different browsers and devices to ensure compatibility and performance.

Conclusion

The declare attribute was part of early HTML specifications intended to declare <object> properties without instantiating embedded content immediately. Its lack of support in modern browsers means it should be avoided in favor of current, effective techniques for managing content loading.

When you encounter declare in old tutorials or legacy pages, treat it as historical context. For new projects, use preload, loading="lazy", and native media elements instead.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about declare

Bookmark these when reading legacy HTML.

5
Core concepts
🗂️ 02

object Only

Legacy embed.

Scope
03

Boolean

Presence = on.

Syntax
📄 04

Declaration

Not loaded.

History
▶️ 05

Use preload

Modern alt.

Today

❓ Frequently Asked Questions

It marked an object as a declaration only, without instantiating the embedded resource until referenced. Modern browsers ignore this.
No. It is obsolete. Use preload, lazy loading, and native HTML5 media elements instead.
Only the <object> element.
Yes. Its presence alone enabled declaration-only mode. There were no other meaningful values.
Use <video> with preload="none", metadata, or auto to control loading.
Yes, with setAttribute and removeAttribute, but this has no effect on loading in modern browsers.

Learn what replaced declare

See historical declare syntax and practice modern preload on video in the Try It editor.

Try video preload example →

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.

3 people found this page helpful