Questions tagged [src]

SRC is a common attribute in HTML used to identify the location of a resource which relates to an element.

Within HTML, several elements may make use of the src attribute in order to identify a resource to which the element may relate. It is normally a "valid non-empty URL potentially surrounded by spaces".

Questions often arise relating to the attribute due to confusion between absolute and relative URLs, how src URLs relate to the location of files, and browser caching.

Some examples of elements which use the src attribute are:

  • IMG

    Specifies a URL referencing a non-interactive, optionally animated, image that is neither paged nor scripted.

  • IFRAME

    Gives the address of a page that the nested browsing context is to contain.

  • SCRIPT

    Gives the address of the external script resource to use.

  • EMBED

    Gives the address of the resource being embedded.

  • VIDEO

    The URL for the video.

  • AUDIO

    The URL for the audio stream.

  • TRACK

    Gives the address of the timed track data. This attribute must be present.

There are other elements which may make use of the src attribute, which may be discovered at the W3C Community Wiki.

Related tags: , , , ,

1612 questions
590
votes
25 answers

Is it possible to set the equivalent of a src attribute of an img tag in CSS?

Is it possible to set the src attribute value in CSS? At present, what I am doing is: and I want it to be something like this .myClass { some-src-property: url("pathTo/myImage.jpg"); I…
Rakesh Juyal
  • 33,043
  • 66
  • 165
  • 212
264
votes
9 answers

Programmatically change the src of an img tag

How can I change the src attribute of an img tag using javascript? at first I have a default src which is "../template/edit.png" and I wanted to change it with "../template/save.png"…
Jam Ville
  • 5,467
  • 8
  • 30
  • 49
178
votes
14 answers

Dynamically add script tag with src that may include document.write

I want to dynamically include a script tag in a webpage however I have no control of it's src so src="source.js" may look like this. document.write(' and the result should be…
Yusaf Khaliq
  • 3,033
  • 10
  • 37
  • 80
1
2 3
99 100