CSS Portal

HTML src Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The HTML src attribute specifies the location (URL) of the external resource or file that should be loaded and displayed by the web browser. Commonly used within <img>, <script>, <iframe>, and <audio> elements, the src attribute tells the browser where to find the image, JavaScript file, webpage, or audio clip that needs to be included or executed as part of the HTML document.

For example, in the <img> tag, the src attribute is used to define the path to the image that should be displayed:

<img src="url_to_image.jpg" alt="description of image">

In the <script> tag, it is used to specify the location of a JavaScript file that should be executed:

<script src="url_to_script.js"></script>

The value of the src attribute is a URL, which can be either an absolute URL (pointing to an external resource) or a relative URL (referring to a file within the same website). It is essential for web developers to ensure that the URLs specified in src attributes are correct and accessible, as incorrect or broken URLs can lead to missing images, non-functional scripts, or other content not being properly loaded on the webpage.

Syntax

<tagname src="URL" />

Values

  • URLURL or path of the source file.

Example

<img src="images/sunset.jpg" alt="Sunset">

Browser Support

The following information will show you the current browser support for the HTML src attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 29th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!