Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
What does language attribute do in tag in Javascript?
The language attribute in the HTML <script> tag was used to specify the scripting language being used, typically "javascript". However, this attribute is now deprecated and should not be used in modern web development.
Historical Usage
In older HTML versions, the language attribute was commonly used to indicate the scripting language:
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
</body>
</html>
Hello World!
Why It's Deprecated
The language attribute was deprecated because:
- JavaScript became the de facto standard for client-side scripting
- The
typeattribute provides the same functionality more precisely - It reduces redundancy in HTML markup
Modern Approach
Today, you should use the type attribute or omit it entirely (JavaScript is the default):
<html>
<body>
<!-- Modern way: type attribute -->
<script type="text/javascript">
document.write("Hello World with type!")
</script>
<!-- Even simpler: no attributes needed -->
<script>
document.write("Hello World - no attributes!")
</script>
</body>
</html>
Hello World with type! Hello World - no attributes!
Comparison
| Approach | Status | Recommendation |
|---|---|---|
<script language="javascript"> |
Deprecated | Don't use |
<script type="text/javascript"> |
Valid but optional | Optional |
<script> |
Modern standard | Recommended |
Conclusion
The language attribute is deprecated and should be avoided. Use type="text/javascript" if needed, or simply use <script> tags without attributes for modern JavaScript.
Advertisements
