DEV Community

Cover image for What is the difference between absolute and relative URLs?
Digital Academy
Digital Academy

Posted on • Originally published at gitdemy.com

What is the difference between absolute and relative URLs?

What is a URL?

URL is the mechanism to fetch resources over the internet. The browsers use this to fetch the data to the user.

URL is the abbreviation of a uniform resource locator. It is commonly known as a web address or internet address of any resource on the web. The resource may be the HTML document, image, audio, video, pdf file, CSS document, etc. In some cases, it may be the possibility the URL is being pointed to a resource that does not exist.

What are the types of URLs?

As I have explained above, any URL is the link of a webpage or files like an image, pdf, audio, or video.

These links have two types

What are relative URLs?

Relative URLs are only paths without a domain name. Relative defines “in relation to” which means the path is related to the current webpage domain name. We can say that relative paths are the reference of the file that is located on the same web address/domain.

Look at the different relative URLs.
<img src="gitdemy-logo.png">
<img src="./gitdemy-logo.png">

The above relative links mean the browser will search the file from the current directory.

What are absolute URLs?

Absolute URL contains both domain name and path. It is the complete information of a file or webpage. These URLs start with any protocol https:// or https://.

The syntax of absolute URL
protocal:://domain-name/path
Absolute URLs are written in the address bar of web browsers. It is the full link of any resources that existed on the webserver.

Examples

https://gitdemy.com
https://gitdemy.com/aritcles
https://gitdemy.com/articles/html
https://gitdemy.com/what-are-hyperlinks-in-html-126

If you want to read full article, click the following
Relative vs Absolute URL

Top comments (0)