Rules Hub
Coding Rules Library
Omit default type attributes in HTML5
Do not specify `type="text/javascript"` for scripts or `type="text/css"` for styles, as they are implied defaults in HTML5.
Bad example
| 1 | <script type="text/javascript" src="/analytics.js"></script> |
| 2 | <style type="text/css"> |
| 3 | body { margin: 0; } |
| 4 | </style> |
Explanation (EN)
The `type` attribute is explicitly set to the default values. This is legacy syntax that adds unnecessary verbosity to the markup without adding any value.
Objašnjenje (HR)
Atribut `type` eksplicitno je postavljen na zadane vrijednosti. Ovo je zastarjela sintaksa koja dodaje nepotrebnu opširnost oznakama bez ikakve stvarne koristi.
Good example
| 1 | <script src="/analytics.js"></script> |
| 2 | <style> |
| 3 | body { margin: 0; } |
| 4 | </style> |
Explanation (EN)
Removing the `type` attribute relies on the standard HTML5 defaults (JavaScript for scripts, CSS for styles). The code is cleaner, shorter, and easier to read.
Objašnjenje (HR)
Uklanjanje atributa `type` oslanja se na standardne HTML5 zadane vrijednosti (JavaScript za skripte, CSS za stilove). Kod je čišći, kraći i lakši za čitanje.