URI and URL sound similar and looks similar and are even used interchangeably. So, what is the difference between a URL and URI? Well, that question causes confusion because a URL is a URI, but a URI is not always a URL. URI stands for Uniform Resource Identifier, which is a string that is used to identify a resource. URL stands for “Uniform Resource Locator” and is a specific type of URI and is used to locate a resource on the Internet.
Now when we know that a URL always is a URI, a better question to ask rather than what separates a URL and URI, would be, "what is a URI?".
A Uniform Resource Identifier (URI) can be a name, locator, or both. So, a URI may state the name (URN) or the location of a resource (URL). A URN and URL is always a URI, but not the other way around. We define a resource's identity with a URN and locate it with a URL.
But what does identifying or locating a resource even mean? The answer is that when we talk about resources, we talk about digital, physical or abstract things that we can identify.
URL is an abbreviation for “Uniform Resource Locator” and is a specific type of URI. An URL identifies resources and provides the network location for the respective resource. This means that a client may use an URL to retrieve a resource.
URN is an abbreviation for Uniform Resource Name. A URN is a URI that is assigned under the "urn" URI scheme and a particular URN namespace, with the intent that the URN will be a persistent, location-independent resource identifier.
The URI syntax consists of the following components in a hierarchical sequence: scheme, authority, path, query, and fragment.
All URI starts with a scheme, which means that how a URI looks like vary depending on which scheme you use. This is because schemes may have their own syntax like
scheme:scheme-specific-part. Down below we see four different URIs:
ftp://ftp.is.co.za/rfc/rfc1808.txt http://www.example.com/article?id=1#middle mailto:firstname.lastname@example.org tel:+1-816-555-1212
Let's look at the following URI
http is the scheme,
www.example.com is the authority,
/article is the path,
?id=1 is the query part, and lastly,
#middle is the fragment part.
Knowing the difference between URI and URL as a web developer is a great idea. If you are a web developer, I recommend that the next time you write some HTML-code, you try different URIs out by using anchor tags. For example like this:
<a href="http://www.example.com">Go to example.com</a> <a href="mailto:John.Smith@example.com">Email John Smith</a> <a href="tel:+numberhere">call +numberhere</a>