HTML - <script> and <noscript> Tag

  • <script>: Adds or links to JavaScript code

  • <noscript>: Provides fallback content when JavaScript is unavailable

 

These two tags are often used together to ensure both functionality and accessibility.

<script> Tag

The <script> tag is used to embed or reference JavaScript code in an HTML document. It allows you to add dynamic behavior to your web page such as form validation, animations, interactive content, etc.

Common attributes:

  1. src – Specifies the path to an external JavaScript file
    Example: <script src="script.js"></script>

  2. type – Specifies the scripting language (default is "text/javascript")
    Example: <script type="text/javascript">

  3. async – Loads the script asynchronously, without blocking the page
    Example: <script src="script.js" async></script>

  4. defer – Delays script execution until the page has finished parsing
    Example: <script src="script.js" defer></script>

Example using inline JavaScript:

<script>
  alert("Welcome to the site!");
</script>

<noscript> Tag

The <noscript> tag is used to define alternate content that is displayed only when the browser does not support JavaScript or if JavaScript is disabled.

It helps provide fallback content for users who cannot run scripts.

Example:

<noscript>
  Your browser does not support JavaScript or it is disabled. Please enable JavaScript for the full experience.
</noscript>