OnlineCBT Logo OnlineCBT
HTML Tutorial
HTML · LESSON 15

Relative vs Absolute URLs

By Ratan Updated: 16 Oct 2026

Understand the key differences between relative file paths and absolute web URLs.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. Understanding URLs in Web Development

Every resource on the World Wide Web—whether a web page, image, stylesheet, or video—is referenced via a Uniform Resource Locator (URL). In HTML, anchor tags () and media sources rely on two fundamental path formats: Relative URLs and Absolute URLs.

2. Absolute URLs

An Absolute URL contains the complete internet address, including the transfer protocol (http:// or https://), domain name, and optional file path.


Browse All Test Series
Search on Google
  • Always use absolute URLs when linking to external domains outside your website.
  • Must include the protocol (https://); omitting it causes the browser to treat it as a local subfolder.

3. Relative URLs

A Relative URL specifies a path relative to the current file's location or the website root. It omits the protocol and domain name, making your codebase fully portable across local development (localhost), staging, and production servers.

Relative Path Syntax Rules:

  • filename.html or ./filename.html: Target file is located in the same directory as current file.
  • subfolder/filename.html: Target file is located inside a child subfolder.
  • ../filename.html: Move up one folder level (parent directory).
  • ../../filename.html: Move up two folder levels.
  • /images/logo.png (Root-relative): Starts from the root directory of the domain, regardless of where current file lives.

About Us


Exam Portal Banner


Student Dashboard

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat