HTML DOM Image src Property (original) (raw)

Last Updated : 23 Jul, 2025

The HTML DOM Image src Property is used to set or returns the value of the src attribute of the element. This attribute is used to specify the URL of the Image.

Syntax:

Property Values: It contains a single value URL that specifies the URL of the document that is embedded in the Image. There are two types of URL links which are listed below:

Return value: It returns a string value that represents the URL of the image.

Example: Below code returns the src Property.

HTML `

GeeksforGeeks

    <h2>HTML DOM Image src Property</h2>

    <img id="GFG" src=

"https://media.geeksforgeeks.org/wp-content/uploads/a1-25.png" width="400" height="150" />

    <button onclick="Geeks()">
        Click me!
    </button>

    <p id="sudo"></p>

</center>

<script>
    function Geeks() {
        var g = document.getElementById("GFG").src;
        document.getElementById("sudo").innerHTML = g;
    }
</script>

`

Output:

Example 2: This example sets the src property.

HTML `

GeeksforGeeks

HTML DOM Image src Property


Click me!

</center>

<script>
    function Geeks() {
      var g = document.getElementById("GFG").src =

"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-300x300.png" document.getElementById("sudo").innerHTML = g; }

`

Output:

Supported Browsers: