src (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

src="uri"

Description

The src attribute tells the browser where to look for the image that should be presented to the user. This image may be located in the same directory as the page that’s referencing the file, in another directory on the same server, or on another server entirely.

The example specifies an image that’s located in the same directory as the web page that’s calling it, but if the submit image was located in a directory that was one level higher than the referencing document, the syntax would be as follows:

<input type="image" src="../submit.jpg"
    alt="Submit your details"/>

Here, ../ equates to "move up one directory in the hierarchy.”

You can also reference an image relative to the web site’s root (the folder or file after the domain name):

<input type="image" src="/submit.jpg"
    alt="Submit your details"/> 

This attribute markup basically says, “display the image submit.jpg that can be found in www.mydomain.com/.” This is a very handy way of referencing files, as you can move the document containing the submit image to another location on the file system without having to change the link.

If you were referencing an image that’s held on another server, you’d express the src using a complete URI, as follows:

<input type="image" src="http://www.some-domain.com/submit.jpg"
    alt="Submit your details"/>  

Example

The src attribute for this image input shows that the image resides in the same directory as the web page that references it:

<form>
  ⋮
  <input type="image" src="submit.jpg" alt="Submit your details"/>
</form>

Value

This attribute takes as its value the location of the button image relative to the referencing document, relative to the server root, or as a complete URI containing http:// or https://, the server name, and the path to the document on that server.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

There are no comments yet.

Related Products