skip to content
vvhybe
the blog

, a 2-minute read

URL, URI, URN: do you know the differences?

Every URL is a URI, so is every URN, and most people use the three words for the same thing. What each one means, and which one to say.

You type one into a browser every day. Some docs call it a URL, some a URI, and older specs talk about URNs. They aren't three rival things: they're one family, and each name says what a member can do.

URI: the family name

A URI, a Uniform Resource Identifier, is any string that identifies a resource, written in one syntax: RFC 3986. The RFC draws its parts like this:

  foo://example.com:8042/over/there?name=ferret#nose
  \_/   \______________/\_________/ \_________/ \__/
   |           |            |            |        |
scheme     authority       path        query   fragment

Only the scheme is required; which other parts appear depends on it. news:comp.infosystems.www.servers.unix has no authority, and it's still a URI. So is urn:ietf:rfc:3986.

URL: a URI that says where

A URL, a Uniform Resource Locator, is a URI that doesn't only name the resource: it tells you how to reach it. https://vvhybe.com/blog/ says use HTTPS, ask the host vvhybe.com, and request /blog/. Every URL is a URI.

URN: a URI that says what

A URN, a Uniform Resource Name, is a URI in the urn: scheme (RFC 8141): a name meant to stay the same for as long as the thing exists, wherever it lives, and whether or not it can be fetched at all. urn:isbn:9780131103627 names a book, the second edition of The C Programming Language, not a copy of it on any shelf.

it answersfor example
URIwhich resourceany of the below
URLwhere it is, and how to get ithttps://vvhybe.com/blog/
URNwhat it is, for goodurn:isbn:9780131103627

in code

The browser's URL parser takes all of them, and hands you the parts:

const page = new URL("https://vvhybe.com/blog/?tag=web#top");
page.protocol; // "https:"
page.host;     // "vvhybe.com"
page.pathname; // "/blog/"
page.search;   // "?tag=web"
page.hash;     // "#top"

const book = new URL("urn:isbn:9780131103627");
book.protocol; // "urn:"
book.pathname; // "isbn:9780131103627"
book.origin;   // "null": a name has nowhere to come from

A path on its own isn't a URI. It's a relative reference: it needs a base to resolve against.

new URL("/blog/");
// TypeError: Invalid URL

new URL("../work/", "https://vvhybe.com/blog/notes/").href;
// "https://vvhybe.com/blog/work/"

which word to say

Here the standards disagree. RFC 3986 asks future documents to say URI rather than the narrower URL and URN. The WHATWG URL Standard, the one browsers implement, went the other way: it says URL for all of them, and calls the split confusing.

So on the web, say URL: that's the word your browser, your fetch calls and your framework use. Say URI when you mean the general syntax, in a spec or an API that takes any scheme. Say URN when you mean a name in the urn: scheme, one that has to outlive any address.