DOM Properties

HTMLImageElement.currentSrc

Returns the absolute URL of the selected image source. It can differ from src when srcset or picture participates. The URL alone does not prove successful decoding. Example result: true.

Formal Syntax & Structure

html syntaxhtml
image.currentSrc

Return Value

string

Selected URL or empty string.

Working Example

Example Snippethtml
<p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  const image = new Image(); image.src = "data:image/svg+xml," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8"><rect width="12" height="8" fill="green"/></svg>');  await image.decode(); result.textContent = image.currentSrc.startsWith("data:image/svg+xml,");  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference