src (input, img)

Jump to: navigation, search

src (input, img)



Needs Summary: This article does not have a summary. Summaries give a brief overview of the topic and are automatically included on some listing pages that link to this article.


Applies to  ?

The required src attribute specifies the URL of the image.

Note: When a web page loads; it is the browser, at that moment, that gets the image from a web server and inserts it into the page. Therefore, make sure that the image actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.

Examples

View live exampleThis example uses the src property to change the image's src attribute.

<body onmousedown="oImage.src='sphere.png'" onmouseup="oImage.src='cone.png'">
... 
	<img id="oImage" src="cone.jpeg">

</body>

Notes

Remarks

The value of the src attribute of the img and input type=image elements depends on the context of the reference to the attribute. When read as a Document Object Model (DOM) attribute, src returns a URL relative to the hosting domain. The value specified by the page author is returned when src is read as a content attribute, when the page is displayed in an earlier document compatibility mode. Windows Internet Explorer 8 or later. In IE8 Standards mode, the value of the src attribute of the img and input type=image elements depends on the context of the reference to the attribute. When read as a DOM attribute, src returns a URL relative to the domain hosting the Web page. The value specified by the page author is returned when src is read as a content attribute, when the page is displayed in an earlier document compatibility mode, or when the page is viewed with an earlier version of the browser. For more information, see Attribute Differences in Internet Explorer 8.

Syntax

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? ? ? ? ?

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?

See also

Related pages (MSDN)

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]