- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - src Attribute
The HTML src attribute is used to represent external resources such as images, videos, audio, and URLs in the page from the external or device resource. In other words, this attribute specifies the location (URL) of the external resource.
The src attribute is applicable to the following elements −
- <audio>
- <embed>
- <img>
- <iframe>
- <input>
- <script>
- <source>
- <track>
- <video>
Syntax
Following is the syntax of the src attribute −
<element src="URL" />
Where, element should be one of the elements listed above.
Example
In the following example, let’s demonstrate the usage of the src attribute in the <input> tag, as follows−
<!DOCTYPE html> <html> <head> <title>HTML input src Attribute</title> <style> body { text-align: center; } </style> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>THE input src Attribute</h2> <form action="https://tutorialspoint.com/" method="post"> <input id="myImage" type="image" src="https://www.tutorialspoint.com/images/logo.png?v2" alt="Submit" width="200" height="60" /> </form> </body> </html>
When we run the above code, it will generate an output consisting of the text along with a image with hyperlink on the webpage. when the user tries to click on the image it will gets redirect.
Example
Considering the following example, where we are going to use the src attribute with the image tag.
<!DOCTYPE html> <html> <head> <title>HTML src Attribute</title> <style> body { text-align: center; } </style> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>HTML src Attribute</h2> <p>src attribute in img to display the external image on the page</p> <img src="https://www.tutorialspoint.com/images/logo.png?v2" alt="logo" /> </body> </html>
On running the above code, the output window will pop up displaying the text along with a image on the webpage.
Example
Let's look at the following example, where we are going to use the src attribute with the video element.
<!DOCTYPE html> <html> <head> <title>HTML src Attribute</title> <style> body { text-align: center; } </style> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>HTML src Attribute</h2> <p>src attribute in video to display the external video on the page</p> <video width="380" height="220" controls> <source src="https://samplelib.com/lib/preview/mp4/sample-5s.mp4" type="video/mp4"> </video> </body> </html>
When we run the above code, it will generate an output consisting of the video displayed on the webpage.
Example
Following is the example, where we are going to use the src attribute with the embed tag.
<!DOCTYPE html> <html> <head> <title>HTML src Attribute</title> <style> body { text-align: center; } </style> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>The embed src attribute</h2> <embed src="https://www.tutorialspoint.com/images/logo.png?v2"> </body> </html>
On running the above code, the output window will pop up displaying the text along with a image on the webpage.
To Continue Learning Please Login
Login with Google