Parts of a URL

A diagram of parts of a URL.To fully understand URLs, it helps to know at least the basic parts of a URL. This is a subject that can actually get quite complicated, and would end up involving a lot of stuff that most of you will never need to know. I will try to keep it simple and focus only on the stuff that you actually need to know to create basic websites. Just realize that I’m leaving a lot of stuff out (and, in fact, there’s a lot of stuff I don’t know about URLs).

The Five Basic Parts of a URL

Just to keep it simple, we’re just going to cover five basic parts of a URL (just know that there are others). Those five parts are as follows…

  1. the protocol
  2. the hostname,
  3. file path,
  4. query,
  5. fragment

The protocol (more correctly known as the scheme) is always followed by a colon and two forward slashes. So, for example, the HTTP protocol would look like this: http://. Most frequently, especially as a beginner, you will really only need to worry about the HTTP protocol. Below is a table showing the anatomy of an HTTP URL.

Parts of a URL
Protocol Hostname File Path Query Fragment
http:// www.mywebsite.com /products/ ?loggedin=true #widget35

All together, that URL would like in the example below…

http://www.mywebsite.com/products/?loggedin=true#widget35

The query part will only be used if you are designing part or all of your site in a server-side scripting language like PHP or ASP…so you can pretty much forget about that right now. But I did want to show it to you because URL queries are quite common.

The fragment is what allows the web browser to scroll to a particular element on the page. Usually an element ID follows the hashmark (#), but the name of an anchor element can also be used. We first encountered the fragment in our lesson on the anchor tag.

Well, now at least you know some of the parts of a URL.

This entry was posted in URL Basics. Bookmark the permalink.

Comments are closed.