Categories
http rfc3986 uri url urn

What is the difference between a URI, a URL and a URN?

4795

People talk about URLs, URIs, and URNs as if they’re different things, but they look the same to the naked eye.

What are the distinguishable differences between them?

9

  • 174

    URL is more specific than URI.

    – mk12

    Dec 31, 2009 at 7:09

  • 34

    Tor the webmasters take on this question: What is difference between URI and URL

    Dec 21, 2012 at 10:14

  • 188

    Mini Venn diagram: ( URIs ( URLs ) )

    – icc97

    Nov 13, 2014 at 15:20

  • 40

    There still seems to be a lot of confusion about URI vs URL, even by those who attempted to answer the question. It would benefit everyone to see practical examples of URLs that are not URIs, examples of URIs that are not URLs, and examples that are URLs and URIs.

    – Dennis

    Feb 8, 2015 at 18:43

  • 37

    Kathy: “Is that your dog?” Bob: “It would be more correct to call him a canine.” Kathy: “No, he’s a dog. You, sir, are a pedant.”

    – Yojimbo

    Jul 20, 2015 at 18:49

1892

From RFC 3986:

A URI can be further classified as a locator, a name, or both. The
term “Uniform Resource Locator” (URL) refers to the subset of URIs
that, in addition to identifying a resource, provide a means of
locating the resource by describing its primary access mechanism
(e.g., its network “location”). The term “Uniform Resource Name”
(URN) has been used historically to refer to both URIs under the
“urn” scheme [RFC2141], which are required to remain globally unique
and persistent even when the resource ceases to exist or becomes
unavailable, and to any other URI with the properties of a name.

So all URLs are URIs, and all URNs are URIs – but URNs and URLs are different, so you can’t say that all URIs are URLs.

If you haven’t already read Roger Pate’s answer, I’d advise doing so as well.

17

  • 17

    Only URIs with the urn: scheme are URNs. A URI could be a classic URL, a URN, or just a URI that doesn’t start with “urn:” and doesn’t refer to a location of a resource.

    Oct 6, 2008 at 21:38

  • 20

    Notall URLs are URIs“. It depends on the interpretation of the RFC. For example in Java the URI parser does not like [ or ] and that’s because the spec says “should not” and not “shall not”.

    – Adam Gent

    May 16, 2013 at 0:47

  • 5

    @AdamGent: RFC 3986 1.1.3: “A URI can be further classified as a locator, a name, or both.” So, if URL is a special kind of URI, that means that every URL is a URI. Doesn’t it?

    – Hubert

    Jun 16, 2013 at 23:32


  • 20

    @AdamGent: That sounds like a Java implementation quirk, and not normative. The java.net.URI doc itself says “every URL is a URI, abstractly speaking, but not every URI is a URL”. And java.net.URL does weird stuff like checking equality of URLs by resolving host names to IP addresses (which seems at odds with RFC 3986 sec 6 in the first place, and breaks w virtual hosts). I think this just means the Java Standard Library has some inconsistent class behavior.

    Mar 11, 2014 at 5:00

  • 5

    @JonSkeet Maybe just need to differentiate between standards vs implementations? E.g. “Formally, according to RFCs, all URLs are URIs. (RFC excerpt.) But existing implementations may not match the spec exactly, possibly for interoperability, and may use URLs that are not valid per the RFCs. And because it’s a complicated area, some people and documents might use ‘URL’ to mean something different from the RFC-specified thing.” Sort of like how most email validation routines don’t match the RFC definitions.

    Mar 11, 2014 at 21:06

1892

From RFC 3986:

A URI can be further classified as a locator, a name, or both. The
term “Uniform Resource Locator” (URL) refers to the subset of URIs
that, in addition to identifying a resource, provide a means of
locating the resource by describing its primary access mechanism
(e.g., its network “location”). The term “Uniform Resource Name”
(URN) has been used historically to refer to both URIs under the
“urn” scheme [RFC2141], which are required to remain globally unique
and persistent even when the resource ceases to exist or becomes
unavailable, and to any other URI with the properties of a name.

So all URLs are URIs, and all URNs are URIs – but URNs and URLs are different, so you can’t say that all URIs are URLs.

If you haven’t already read Roger Pate’s answer, I’d advise doing so as well.

17

  • 17

    Only URIs with the urn: scheme are URNs. A URI could be a classic URL, a URN, or just a URI that doesn’t start with “urn:” and doesn’t refer to a location of a resource.

    Oct 6, 2008 at 21:38

  • 20

    Notall URLs are URIs“. It depends on the interpretation of the RFC. For example in Java the URI parser does not like [ or ] and that’s because the spec says “should not” and not “shall not”.

    – Adam Gent

    May 16, 2013 at 0:47

  • 5

    @AdamGent: RFC 3986 1.1.3: “A URI can be further classified as a locator, a name, or both.” So, if URL is a special kind of URI, that means that every URL is a URI. Doesn’t it?

    – Hubert

    Jun 16, 2013 at 23:32


  • 20

    @AdamGent: That sounds like a Java implementation quirk, and not normative. The java.net.URI doc itself says “every URL is a URI, abstractly speaking, but not every URI is a URL”. And java.net.URL does weird stuff like checking equality of URLs by resolving host names to IP addresses (which seems at odds with RFC 3986 sec 6 in the first place, and breaks w virtual hosts). I think this just means the Java Standard Library has some inconsistent class behavior.

    Mar 11, 2014 at 5:00

  • 5

    @JonSkeet Maybe just need to differentiate between standards vs implementations? E.g. “Formally, according to RFCs, all URLs are URIs. (RFC excerpt.) But existing implementations may not match the spec exactly, possibly for interoperability, and may use URLs that are not valid per the RFCs. And because it’s a complicated area, some people and documents might use ‘URL’ to mean something different from the RFC-specified thing.” Sort of like how most email validation routines don’t match the RFC definitions.

    Mar 11, 2014 at 21:06

768

URI — Uniform Resource Identifier

URIs are a standard for identifying documents using a short string of numbers, letters, and symbols. They are defined by RFC 3986 – Uniform Resource Identifier (URI): Generic Syntax. URLs, URNs, and URCs are all types of URI.

URL — Uniform Resource Locator

Contains information about how to fetch a resource from its location. For example:

  • http://example.com/mypage.html
  • ftp://example.com/download.zip
  • mailto:[email protected]
  • file:///home/user/file.txt
  • tel:1-888-555-5555
  • http://example.com/resource?foo=bar#fragment
  • /other/link.html (A relative URL, only useful in the context of another URL)

URLs always start with a protocol (http) and usually contain information such as the network host name (example.com) and often a document path (/foo/mypage.html). URLs may have query parameters and fragment identifiers.

URN — Uniform Resource Name

Identifies a resource by a unique and persistent name, but doesn’t necessarily tell you how to locate it on the internet. It usually starts with the prefix urn: For example:

  • urn:isbn:0451450523 to identify a book by its ISBN number.
  • urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66 a globally unique identifier
  • urn:publishing:book – An XML namespace that identifies the document as a type of book.

URNs can identify ideas and concepts. They are not restricted to identifying documents. When a URN does represent a document, it can be translated into a URL by a “resolver”. The document can then be downloaded from the URL.

URC — Uniform Resource Citation

Points to meta data about a document rather than to the document itself. An example of a URC is one that points to the HTML source code of a page like: view-source:http://example.com/

Data URI

Rather than locating it on the internet, or naming it, data can be placed directly into a URI. An example would be data:,Hello%20World.


Frequently Asked Questions

I’ve heard that I shouldn’t say URL anymore, why?

The W3 spec for HTML says that the href of an anchor tag can contain a URI, not just a URL. You should be able to put in a URN such as <a href="urn:isbn:0451450523">. Your browser would then resolve that URN to a URL and download the book for you.

Do any browsers actually know how to fetch documents by URN?

Not that I know of, but modern web browser do implement the data URI scheme.

Does the difference between URL and URI have anything to do with whether it is relative or absolute?

No. Both relative and absolute URLs are URLs (and URIs.)

Does the difference between URL and URI have anything to do with whether it has query parameters?

No. Both URLs with and without query parameters are URLs (and URIs.)

Does the difference between URL and URI have anything to do with whether it has a fragment identifier?

No. Both URLs with and without fragment identifiers are URLs (and URIs.)

Does the difference between URL and URI have anything to do with what characters are permitted?

No. URLs are defined to be a strict subset of URIs. If a parser allows a character in a URL but not in a URI, there is a bug in the parser. The specs go into great detail about which characters are allowed in which parts of URLs and URIs. Some characters may be allowed only in some parts of the URL, but characters alone are not a difference between URLs and URIs.

But doesn’t the W3C now say that URLs and URIs are the same thing?

Yes. The W3C realized that there is a ton of confusion about this. They issued a URI clarification document that says that it is now OK to use the terms URL and URI interchangeably (to mean URI). It is no longer useful to strictly segment URIs into different types such as URL, URN, and URC.

Can a URI be both a URL and a URN?

The definition of URN is now looser than what I stated above. The latest RFC on URIs says that any URI can now be a URN (regardless of whether it starts with urn:) as long as it has “the properties of a name.” That is: It is globally unique and persistent even when the resource ceases to exist or becomes unavailable. An example: The URIs used in HTML doctypes such as http://www.w3.org/TR/html4/strict.dtd. That URI would continue to name the HTML4 transitional doctype even if the page on the w3.org website were deleted.


URI/URL Venn Diagram

5

  • 8

    is “C:\myfile” an URI,URL or URN ? or none of them.

    – bvdb

    May 18, 2015 at 7:36

  • 15

    A file path is not a URL or URI unless you put the file:// prefix on it. Although browsers do generally handle non-URL formatted file paths. Mozilla publishes their test cases for file URLs.

    Jun 8, 2015 at 16:19


  • 2

    See section 1.1 of the RFC — “Uniformity provides several benefits. It allows different types of resource identifiers to be used in the same context, even when the mechanisms used to access those resources may differ. It allows uniform semantic interpretation of common syntactic conventions across different types of resource identifiers…”

    Jul 5, 2015 at 2:11

  • 6

    This answer is a lot more easy to understand. I can see the clearly pictures of real example of the URLs & URN. And for anyone to read more about this… danielmiessler.com/study/url-uri

    – vee

    May 22, 2017 at 7:41

  • 1

    Thank you for making it clear that URIs still have standardized syntax, albeit more flexible than URLs. Daniel Miessler’s blog post (linked in the comment above) misses this point.

    – bb010g

    Jul 10, 2020 at 19:50