<script>

Document

Embeds or references executable JavaScript code. Can be placed in the head or body, with defer or async attributes for loading control.

Common Attributes

srctypeasyncdefercrossoriginnoncenomodule

Example

<script src="/app.js" defer></script>
<script>
  console.log('Hello');
</script>

About the <script> Element

The <script> HTML element belongs to the Document category of HTML elements. Embeds or references executable JavaScript code. Can be placed in the head or body, with defer or async attributes for loading control. Understanding when and how to use this element is essential for building well-structured, accessible, and SEO-friendly web pages.

The <script> element requires both an opening <script> and closing </script> tag. Content placed between these tags becomes the element's children. This element is part of the current HTML Living Standard and is supported in all modern browsers including Chrome, Firefox, Safari, and Edge.

Proper use of semantic HTML elements like <script> improves document structure, helps screen readers interpret content correctly, and provides signals to search engines about the purpose of different sections of your page. This leads to better accessibility scores, improved SEO rankings, and more maintainable code.

Related Elements