Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 2 of 9
URL Anatomy & Path Types
Understanding URLs (Uniform Resource Locators) is essential for web development. A URL is an address that tells the browser exactly where to find a resource on the internet. Every link you create uses a URL, so understanding their structure helps you write correct links and debug navigation issues.
URL Structure Breakdown
A URL has several parts:
https://www.example.com:443/blog/post?id=5&sort=date#comments
- 1Protocol (https://) β How the browser communicates with the server.
- 2Domain (www.example.com) β The server's address.
- 3Port (:443) β Default for HTTPS.
- 4Path (/blog/post) β The specific page or resource.
- 5Query String (?id=5&sort=date) β Extra data sent to the server.
- 6Fragment (#comments) β Jumps to a specific section on the page.
Path Types:
β’ Absolute URL: https://www.example.com/page
β’ Root-relative: /page
β’ Relative: page.html or ../page.html
Understanding absolute vs relative URL paths in HTML links
Path Types Comparison
- Absolute (https://example.com/page) β Full URL. Use for external links.
- Root-relative (/blog/page.html) β From domain root. Best for internal links.
- Relative (page.html) β Same folder. Breaks if file moves.
- Relative parent (../page.html) β One folder UP.
- Fragment only (#section) β Same page anchor.
Quick Quiz
Key Takeaways
- Understanding URLs (Uniform Resource Locators) is essential for web development.
- Absolute (https://example.com/page) β Full URL. Use for external links.
- Root-relative (/blog/page.html) β From domain root. Best for internal links.
- Relative (page.html) β Same folder. Breaks if file moves.
Finished this lesson?