Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

HTML Basic

HTML Reference

HTML version Attribute

Posted in HTML Tutorial
Updated on Sep 22, 2024
By Mari Selvan
👁️ 66 - Views
⏳ 4 mins
💬 1 Comment
HTML version Attribute

Photo Credit to CodeToFun

🙋 Introduction

The version attribute in HTML is used to specify the version of the HTML standard that a document adheres to. Although it was used in early versions of HTML, it is now considered obsolete and is not supported in HTML5.

Understanding the historical context and use of this attribute can provide insight into the evolution of HTML standards.

🎯 Purpose of version

In early HTML specifications, the version attribute was used to declare the version of HTML a document was written in. This helped browsers to render the content correctly according to the specified standard. However, as HTML evolved, this attribute was phased out in favor of other methods, such as the <!DOCTYPE> declaration, which serves a similar purpose in modern HTML.

💎 Values

The version attribute could take specific values corresponding to different versions of HTML. Here are some examples of the values that were used:

  • HTML 2.0: version="2.0"
  • HTML 3.2: version="3.2"
  • HTML 4.01: version="4.01"

📄 Implementation Example:

Although the version attribute is obsolete, here is an example of its usage in an older HTML document:

index.html
Copied
Copy To Clipboard
<html version="4.01">
<head>
  <title>Example with version attribute</title>
</head>
<body>
  <h1>Hello, World!</h1>
  <p>This is an example of an HTML document with the version attribute.</p>
</body>
</html>

🧠 How it Works

In this example, the version attribute is set to "4.01", indicating that the document adheres to HTML 4.01 standards.

🔄 Dynamic Values with JavaScript

While the version attribute is obsolete and not applicable in modern HTML, it is still possible to manipulate attributes dynamically using JavaScript for educational or experimental purposes. Here’s how you could set an attribute dynamically:

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html>
<head>
  <title>Dynamic Version Attribute Example</title>
  <script>
    // Dynamically set the version attribute (for demonstration purposes only)
    document.addEventListener("DOMContentLoaded", function() {
      document.documentElement.setAttribute("version", "4.01");
    });
  </script>
</head>
<body>
  <h1>Hello, World!</h1>
  <p>This demonstrates setting a version attribute dynamically with JavaScript.</p>
</body>
</html>

🧠 How it Works

In this script, the version attribute is set dynamically for the html element when the document content is loaded. This is purely for demonstration, as modern HTML does not utilize this attribute.

🏆 Best Practices

  • Avoid using obsolete attributes like version in modern web development.
  • Use the <!DOCTYPE> declaration to specify the HTML version for modern documents. For example, use <!DOCTYPE html> for HTML5.
  • Keep your HTML code up-to-date with current standards to ensure compatibility and proper rendering across all browsers.

🎉 Conclusion

The version attribute in HTML was historically used to declare the version of HTML a document adhered to, but it is now obsolete.

Understanding its purpose and usage helps appreciate the evolution of HTML standards. In modern web development, always use the <!DOCTYPE> declaration to specify the HTML version.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy