Using HTML , vous indiquez l’utilisation de scripts dans vos documents HTML. En plus de l’intégration directe de code JavaScript, il est également possible de faire référence à des scripts externes. Il existe différents attributs optionnels tels que async ou defer qui régissent l’utilisation des scripts utilisés.
Qu’est-ce que le tag HTML et à quoi sert-il ?
La balise HTML (ou tag HTML en anglais) sert à intégrer des scripts côté client dans des pages Web ou des documents HTML. Dans les balises d’ouverture et de fermeture , vous pouvez soit donner des instructions de script directes, soit faire référence à un fichier de script externe à l’aide de l’attribut src. Depuis HTML5, JavaScript est devenu le langage de script par défaut ; dans les versions HTML antérieures, une indication supplémentaire du langage de script était nécessaire.
Les utilisations typiques de HTML ou de JavaScript sont généralement la validation des entrées de formulaires, la manipulation d’images et les modifications dynamiques du contenu d’un site Web.
- 3x plus rapide, 60 % d’économie
- Haute disponibilité >99,99 %
- Seulement chez IONOS : jusqu’à 500 Go inclus
Tag HTML : syntaxe et exemple de code
La syntaxe de l’élément est relativement simple : une balise d’introduction marque le début du script, une balise de fermeture marque la fin du script.
html
If you write the JavaScript code directly in the element, you don't need any other parameters. If you are referring to an external script, you must also insert the HTML attribute src (for English source). Syntax for HTML prend alors la forme suivante :
Exemple d’intégration directe de JavaScript
Nous illustrons la syntaxe et le fonctionnement de l’intégration directe de JavaScript avec la balise HTML par un exemple simple. Dans la section , nous plaçons un bouton avec l’attribut id="monbouton". Ensuite, nous intégrons du code JavaScript pour qu’une boîte de dialogue affiche le message « Vous avez cliqué sur le bouton ! » dès qu’un utilisateur clique sur le bouton.
html
Advice
It is recommended to include a alternative text which will be displayed if the script cannot be executed, for example, if a user has disabled JavaScript. For this you can use the element surrounded by its opening and closing tags.
Example of integrating an external script
We transpose this example to the alternative possibility of integrating JavaScript code as an external script. The code of clickable buttonwhich displays the message “You clicked the button!” » after a click, is saved in a new file named script.js :
// script.js
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('monbouton').addEventListener('click', function() {
alert('Vous avez cliqué sur le bouton !')
});
});
javascript
In the second step, we embed the script into an HTML document which is located in the same directory that the script:
What are the attributes of the HTML tag ?
The HTML tag can be combined with several important attributes, including:
async: this attribute allows you to download and execute an external script in parallel with the interpretation of the page code, as soon as it is available, even if the page is not yet fully loaded.crossorigin: Use this attribute to set the HTTP request mode for the script when using CORS.defer: If this attribute is present, an external script is downloaded alongside the interpretation of the page code, but it will only be executed once the entire page has been completely loaded.integrity: to strengthen security, you can add the attributeintegrityto the HTML tag. It allows browsers to verify that the called script has not been modified, ensuring that code is not loaded if the source file has been manipulated.nomodule: this attribute prevents the execution of scripts in browsers that support ES2015 modules.referrerpolicy: Use this attribute to specify what referrer information should be sent when calling a script. Possible values includeno-referrer(no referent information) andstrict-origin(only the original domain is sent).src: This attribute specifies the URL of an external script.type: although now optional, this attribute allows you to specify the content type of the element. In addition to classic scripts, it can be used for ECMAScript modules (module) or for import cards (importmap) containing rules for importing ECMAScript modules.
Domain name
Your domain in one click
- 1 Wildcard SSL certificate per contract
- Included Domain Connect feature for simplified DNS setup

