Beginner LevelHTML & Semantic Web
What is the difference between relative and absolute URLs in HTML links and assets?
❓ Interview Prompt: Compare Absolute URLs (full scheme + domain) vs Relative URLs (path relative to current directory or domain root).
1. Absolute URLs:
Includes full protocol scheme and domain name ('https://example.com/images/logo.png'). Required when referencing external third-party assets.
2. Relative URLs:
Points to files relative to current page location or domain root:
•
'images/logo.png': Relative to current directory.
•
'../logo.png': Relative to parent directory.
•
'/images/logo.png': Domain root-relative path.
Code Implementation Example
html
<!-- Absolute URL (External site) -->
<a href="https://cdn.example.com/file.pdf">External File</a>
<!-- Root-Relative URL (Internal asset) -->
<img src="/assets/images/hero.jpg" alt="Hero Banner">💡Comparing absolute external URLs vs root-relative internal URLs.
🎯 Interview Key Takeaway
Use root-relative URLs (/assets/img.png) for internal application links, and absolute URLs for external resources.
#URLs#Relative Path#Absolute Path#Beginner
Back to all HTML & Semantic Web Questions→