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.
Fundamentals
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.
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.
Reference
💎 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) --><objectdata="file.pdf"type="application/pdf"declare></object><!-- Normal object (still valid for some embeds) --><objectdata="file.pdf"type="application/pdf"></object>
Cheat Sheet
⚡ Quick Reference
Item
Details
Today
Element
<object> only
Still valid element
Type
Boolean attribute
Obsolete
Historical effect
Declare, don’t instantiate
Ignored
JS add
setAttribute("declare", "")
No practical effect
JS remove
removeAttribute("declare")
Safe cleanup
Modern alt
preload, loading="lazy"
Use these
Scope
Applicable Elements
Element
Supported?
Notes
<object>
Was yes (obsolete)
Only element that used declare
<video>, <audio>
No
Use preload instead
<img>, <iframe>
No
Use loading="lazy"
<script>
No
Use defer or async
Compare
declare vs modern loading controls
Goal
Obsolete approach
Modern approach
Delay video load
<object declare>
<video preload="none">
Lazy images
Not applicable
<img loading="lazy">
Defer scripts
Not applicable
<script defer>
Lazy iframes
Not applicable
<iframe loading="lazy">
Hands-On
Examples Gallery
Historical declare syntax, JavaScript toggle, and a modern preload alternative.
Implementation Example
index.html
<objectdata="movie.mp4"type="video/mp4"declare><p>Your browser does not support HTML5 video.</p></object>
Modern browsers ignore declare. For video, use <video>.
Object embed area (declare has no effect today)
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):
preload="none", metadata, or auto on <video> and <audio> gives you explicit, supported control over when media data is fetched.
A11y
♿ 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.
Compatibility
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 attributeObsolete
Bottom line: Do not use declare in new code. Remove it from legacy markup when you find it.
Pro Tips
💡 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.
Wrap Up
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.