<script>...</script>

HTML4 HTML5

The <script> tag is used to embed or include external executable scripts in a web page – most commonly written in JavaScript[cite: 3]. It adds interactivity, handles events, manipulates document structure (DOM), or communicates with the server[cite: 3].

Both opening and closing tags are mandatory, even if the script is imported from an external file via the src attribute[cite: 3].

Attributes:

Example

In the example below, the script fetches a button from the document and displays a simple browser alert when clicked[cite: 3]:

Code:

<button id="demo-btn">Click me</button>
<script>
  document.getElementById('demo-btn').addEventListener('click', function() {
  alert('Hello! The JavaScript script worked correctly.'); });
</script>

The browser will interpret this code as follows (button will be active and respond to clicks)[cite: 3]: