HTML Uniform Resource Locators
HTML Uniform Resource Locators (URLs) are used to specify the addresses of resources, such as web pages, images, stylesheets, scripts, or other types of files, on the internet. A URL is a string of characters that provides a reference to the location of a resource on the web. URLs are an essential component of HTML, as they enable the linking and retrieval of resources needed to render a web page.
A URL is typically composed of several components:
Scheme:
- The scheme indicates the protocol used to access the resource. Common schemes include "http," "https," "ftp," "mailto," etc. For web pages, "http" and "https" are the most common schemes, where "http" is used for unsecured connections, and "https" is used for secured (encrypted) connections.
Host:
- The host specifies the domain name or IP address of the server where the resource is located. For example, in the URL "https://www.example.com/page.html," "www.example.com" is the host.
Port:
- The port number is optional and indicates a specific communication endpoint on the server. If not specified, the default port for the given scheme is assumed (e.g., 80 for "http," 443 for "https").
Path:
- The path specifies the location of the resource on the server's file system. It is often used to point to a specific file or directory. In the URL "https://www.example.com/path/page.html," "/path/page.html" is the path.
Query Parameters:
- Query parameters provide additional information to the server about the request. They are included after the path and are separated by the "?" symbol. For example, in the URL "https://www.example.com/search?q=term," "q=term" is a query parameter indicating a search term.
Fragment Identifier:
- The fragment identifier, often preceded by the "#" symbol, points to a specific section or anchor within the resource. It is used to navigate to a specific part of a document. For example, in the URL "https://www.example.com/page.html#section," "#section" is the fragment identifier.
Here's an example of a complete URL
Example
https://www.example.com:8080/path/page.html?q=search#sectionYou can click on above box to edit the code and run again.
Output
- Scheme: "https"
- Host: "www.example.com"
- Port: "8080"
- Path: "/path/page.html"
- Query Parameter: "q=search"
- Fragment Identifier: "section"
HTML uses URLs in various elements, such as <a> (anchor) for links, <img> for images, <link> for stylesheets, <script> for scripts, and more. The correct use of URLs is crucial for building functional and interconnected web pages.