Skip to main content

HTML Uniform Resource Locators

HTML URLs (Uniform Resource Locators) are used to identify and locate resources on the internet. URLs consist of several parts, including the scheme, the host, the path, and optional query parameters and fragment identifiers.

Here is a breakdown of the different parts of an HTML URL:

  • Scheme: The scheme indicates the protocol used to access the resource. Common schemes include "http://" and "https://", which are used for web pages, and "ftp://", which is used for file transfers.

  • Host: The host specifies the domain name or IP address of the server that hosts the resource. For example, in the URL "http://www.example.com/index.html", the host is "www.example.com".

  • Path: The path specifies the location of the resource on the server. It is a series of directories and filenames that lead to the resource. For example, in the URL "http://www.example.com/index.html", the path is "/index.html".

  • Query Parameters: Query parameters can be used to provide additional information to the server about the resource being requested. They are separated from the path by a question mark ("?") and consist of key-value pairs separated by ampersands ("&"). For example, in the URL "http://www.example.com/search?q=html+urls", the query parameter is "q=html+urls".

  • Fragment Identifier: The fragment identifier is used to indicate a specific section or location within the resource being requested. It is separated from the rest of the URL by a hash symbol ("#"). For example, in the URL "http://www.example.com/index.html#section2", the fragment identifier is "section2".

Here are some common URL schemes

  • http://: Used for accessing resources on the World Wide Web through the HTTP protocol.

  • https://: Used for accessing secure resources on the World Wide Web through the HTTPS protocol.

  • ftp://: Used for accessing files and directories on remote servers through the FTP protocol.

  • mailto: Used to create links that automatically open the user's default email client with a pre-populated email address.

  • tel: Used to create links that initiate phone calls or open the phone dialer with a pre-populated phone number.

  • file://: Used to access files and directories on the user's local file system.

  • data: Used to embed small data files, such as images or audio, directly into the HTML document.

  • javascript: Used to execute JavaScript code directly within the HTML document.

URL Encoding

URL encoding is the process of converting text strings into a format that can be safely transmitted over the internet. URLs may contain special characters such as spaces, ampersands, and other characters that have special meanings in the URL syntax. URL encoding replaces these special characters with percent-encoded sequences, which consist of a percent sign followed by two hexadecimal digits that represent the ASCII code of the character.

As an example:

The space character, which is not allowed in URLs, is encoded as "%20".

  • The ampersand character, which is used to separate different parameters in the query string, is encoded as "%26".
  • This ensures that the URL can be correctly interpreted by web browsers and other software that processes URLs.

There are several libraries and tools available for encoding and decoding URLs, including built-in functions in programming languages such as JavaScript and PHP, and online tools that allow you to encode and decode URLs manually.