HTML src Attribute
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.
Applies To
The src
attribute can be used on the following html elements.
Example
<img src="images/sunset.jpg" alt="Sunset">
Browser Support
The following table will show you the current browser support for the HTML src
Attribute.
Desktop | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
|
Yes | Yes | Yes | Yes | Yes |
Tablets / Mobile | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes | Yes |
Last updated by CSSPortal on: 29th March 2024