HTML Uniform Resource Locators (URLs)

HTML Tutorial

HTML Uniform Resource Locators (URLs)

A HTML Uniform Resource Locators (URLs) is the address of a resource on the web—like a webpage, image, CSS file, video, or API endpoint.

HTML uses URLs to link, load, and reference these resources.


 1. What Is a URL?

A URL tells the browser:

  • Where a resource is located

  • How to access it

Example:

https://www.example.com/images/logo.png

 2. Parts of a URL (Anatomy)

https://www.example.com:443/path/file.html?search=html#top
PartMeaning
https://Protocol (scheme)
www.example.comDomain
:443Port (optional)
/path/file.htmlPath
?search=htmlQuery string
#topFragment (anchor)

 3. Absolute vs Relative URLs (Very Important)

Absolute URL

A complete web address.

  • Works from anywhere
  •  Less portable

Relative URL (Recommended for sites)

Based on the current file’s location.

  •  Short & portable
  • Best for local projects

 4. Root-Relative URLs

Start from the site root.

  •  Great for large sites
  • Requires correct server root

 5. URLs in Common HTML Elements

 Links

Images

 CSS

 JavaScript

 Iframes


 6. URL Protocols You’ll See

ProtocolUse
http / httpsWeb pages
ftpFile transfer
mailtoEmail links
telPhone calls
fileLocal files (limited)

Examples:


7. Query Strings (Passing Data)

In the URL:

search.html?q=html&page=1

 Used for filters, searches, tracking


 8. URL Fragments (Anchors)

Jump to a specific section on a page.


 


 9. URL Encoding (Special Characters)

Spaces and special characters must be encoded.

CharacterEncoded
Space%20
&%26
?%3F

Example:

search.html?q=web%20design

 Common URL Mistakes

  • Using Windows paths (C:\folder\file)
  • Backslashes \ instead of
  •  Wrong case (Logo.pnglogo.png)
  • Missing protocol (https://) in absolute URLs
  •  Broken relative paths

Quick Reference

TypeExample
Absolutehttps://example.com/page.html
Relativepage.html, images/img.png
Root-relative/images/img.png
Query?id=10&sort=asc
Fragment#section

 Key Takeaways

  • URLs point to resources

  • Prefer relative URLs for site files

  • Understand absolute vs relative

  • Use proper encoding

  • URLs are everywhere in HTML

You may also like...