Чем src отличается от href
Перейти к содержимому

Чем src отличается от href

  • автор:

what is the difference between rel and href and src in HTML

all of : href src rel attributes all seems to have same function so why each html element use these different attributes . So what is the function of each of these attributes and when to use each one of them

21.1k 71 71 gold badges 78 78 silver badges 104 104 bronze badges
asked Apr 5, 2020 at 23:32
79 2 2 silver badges 7 7 bronze badges

1 Answer 1

href
The href attribute specifies the location(URL) of any resource that anchor tag points to.
src

The src attribute specifies the location(URL) of any resource that needs to be embedded into the present HTML document. Resourse pointed by src attribute is linked to the current document such as img, video, audio, or script. The browser will allocate screen real estate depending upon the physical dimensions of the embedded object. href has no such provision.

The ***rel*** attribute defines the relationship that the linked resource has to the document from which it’s referenced. In most cases, this resource will simply be “stylesheet“, which means, not surprisingly, “the referenced document is a style sheet .” Related to this value is alternate , which is used alongside the stylesheet value (rel=»alternate stylesheet») to indicate that there’s another style associated with the page. In fact, you can define several alternative styles, although the main issue with this approach lies in making it clear to the user that an alternative style sheet is available. In Firefox, you can chose View > Page Style and pick from the available style sheets on offer, but there’s no obvious indication in any browser that these alternatives exist—it’s usually left to the developer to provide some kind of JavaScript-based style switcher that renders as a control on the page. The following markup shows a page that has one main style sheet and two alternatives:

How href attribute is different from src attribute in HTML ?

href Attribute

  • Usage: The href attribute is primarily associated with hyperlinks ( anchor elements) and is used to define the URL or path to the linked resource.
  • Functionality: It specifies the destination of the hyperlink, whether it’s a web page, an external resource, or an internal anchor within the same page.

Syntax

src Attribute

  • Usage: The src attribute is commonly used with elements like , , , and others. It specifies the source URL or path for embedding external content.
  • Functionality: It defines the source of the content to be embedded, whether it’s an image, a script, an audio or video file, etc.

Syntax

Like Article
Suggest improvement
Share your thoughts in the comments
Add Your Comment

Please Login to comment.

Similar Reads

Why card images use data-src (not src) for image in Bootstrap 4 ?
HTML | src Attribute
HTML | src Attribute
HTML |
HTML |src Attribute HTML |
HTML |
HTML |
HTML |src Attribute
HTML | src Attribute
Article Tags :

advertisewithusBannerImg

Explore More

A-143, 9th Floor, Sovereign Corporate Tower, Sector-136, Noida, Uttar Pradesh — 201305

GFG App on Play Store GFG App on App Store

  • Company
  • About Us
  • Legal
  • Careers
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Explore
  • Hack-A-Thons
  • GfG Weekly Contest
  • DSA in JAVA/C++
  • Master System Design
  • Master CP
  • GeeksforGeeks Videos
  • Geeks Community
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning Tutorial
  • ML Maths
  • Data Visualisation Tutorial
  • Pandas Tutorial
  • NumPy Tutorial
  • NLP Tutorial
  • Deep Learning Tutorial
  • HTML & CSS
  • HTML
  • CSS
  • Web Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind CSS
  • SASS
  • LESS
  • Web Design
  • Django Tutorial
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • DevOps
  • Git
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • Competitive Programming
  • Top DS or Algo for CP
  • Top 50 Tree
  • Top 50 Graph
  • Top 50 Array
  • Top 50 String
  • Top 50 DP
  • Top 15 Websites for CP
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • JavaScript
  • JavaScript Examples
  • TypeScript
  • ReactJS
  • NextJS
  • AngularJS
  • NodeJS
  • Lodash
  • Web Browser
  • Preparation Corner
  • Company-Wise Recruitment Process
  • Resume Templates
  • Aptitude Preparation
  • Puzzles
  • Company-Wise Preparation
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • World GK
  • Management & Finance
  • Management
  • HR Management
  • Finance
  • Income Tax
  • Organisational Behaviour
  • Marketing
  • Free Online Tools
  • Typing Test
  • Image Editor
  • Code Formatters
  • Code Converters
  • Currency Converter
  • Random Number Generator
  • Random Password Generator
  • More Tutorials
  • Software Development
  • Software Testing
  • Product Management
  • SAP
  • SEO — Search Engine Optimization
  • Linux
  • Excel
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Data Science
  • CS Subjects

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It !

Improvement
Please go through our recently updated Improvement Guidelines before submitting any improvements.

This article is being improved by another user right now. You can suggest the changes for now and it will be under the article’s discussion tab.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!

Suggest changes
Please go through our recently updated Improvement Guidelines before submitting any improvements.
Suggest Changes

Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.

geeksforgeeks-suggest-icon

Create Improvement

Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *