


What is the difference between an absolute and a relative URL in HTML?
Sep 16, 2025 am 07:57 AMAn absolute URL includes the full web address with protocol and domain, while a relative URL specifies a path relative to the current page. 1. Use absolute URLs for external websites, ensuring links work anywhere, and when content may be shared. 2. Use relative URLs for internal site navigation, when the site might move domains, or to keep code clean. 3. Absolute URLs always point to the same location and include the domain; relative URLs depend on the current page and lack the domain. 4. Absolute URLs remain valid if the site moves; relative URLs may break if directory structure changes. 5. Absolute means "go exactly here," relative means "go this way from where you are now," with both serving distinct navigation purposes.
The difference between an absolute and a relative URL in HTML comes down to how the link is structured and where it points.

Absolute URL: Full Web Address
An absolute URL includes the complete address of a resource, starting with the protocol (like http://
or https://
), the domain name, and optionally the path to a specific file or page.
Example:

<a href="https://www.example.com/blog/post.html">Visit the blog</a>
? Use absolute URLs when:
- Linking to external websites
- Ensuring the link works no matter the current page or domain
- You're building content that might be shared or syndicated (like in RSS feeds or emails)
They’re unambiguous — the browser always knows exactly where to go.

Relative URL: Path Relative to Current Location
A relative URL specifies the path to a resource relative to the current page’s location. It doesn’t include the protocol or domain.
Example:
If you're on https://www.example.com/about.html
, and you use:
<a href="contact.html">Contact Us</a>
The browser will look for https://www.example.com/contact.html
.
Other examples:
-
./images/photo.jpg
→ looks in the current directory’simages
folder -
../files/doc.pdf
→ goes up one directory, then intofiles
? Use relative URLs when:
- Linking to pages within the same website
- Building a site that may move domains or be developed locally
- Keeping your code cleaner and easier to maintain on large internal sites
Key Differences at a Glance
Feature | Absolute URL | Relative URL |
---|---|---|
Includes domain | Yes (https://www.example.com ) |
No |
Works independently | Yes — always points to the same place | Depends on current page location |
Best for | External links | Internal site navigation |
Affected by site move | No — stays valid | Yes — may break if structure changes |
So, if you're linking to a different website, always use an absolute URL. If you're moving around within your own site, relative URLs are usually simpler and more flexible.
Basically, absolute tells the browser "go exactly here," while relative says "go this way from where you are now."
The above is the detailed content of What is the difference between an absolute and a relative URL in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

1. Go to the official website to download: https://www.consul.io/downloads.html2. Decompression: 3. Set environment variables: path to add E:\programfiles\consul; 4.cmd start: consulagent-dev5. Open the URL: http://localhost:8500, you can see the interface and the interface discovered by related services.

Use single quotes or escaped double quotes to output HTML in PHP. It is recommended to wrap strings with single quotes to avoid attribute quotation conflicts. Dynamic content can be generated in combination with variable splicing or heredoc syntax.

Use the autoplay, muted and playsinline properties to achieve silent automatic playback of HTML videos. Most modern browsers require the video to be muted to play automatically, muted meets this condition, playsinline ensures iOSSafari inline playback instead of full screen, controls are optionally used to display the control bar. If you need to unmute, you can set video.muted=false after user interaction through JavaScript. When triggering programmatically, it must also be set to mute first and catch possible errors. Correctly add these properties and confirm the file path to achieve cross-device compatible silent automatic playback.

Usetype="tel"inHTMLinputtocreateatelephonefield,whichoptimizesmobilekeyboardsandimprovesuserexperience;enhanceitwithattributeslikepattern,required,maxlength,andautocompleteforvalidationandusability.

Use Flexbox, inline-block or Grid to display HTML elements side by side: 1. Flexbox is the most recommended, implemented through display:flex; 2. Inline-block should pay attention to the blank spacing; 3. Grid is suitable for complex layouts, and use grid-template-columns to define columns.

To add a border to an HTML table, use the CSS border property and set border-collapse:collapse. First create a table structure containing th and td elements, and then add 1pxsolidblack and other border styles to the table, th, and td through inline, internal or external CSS. It is recommended to use internal CSS to uniformly control the style to ensure a clean and consistent appearance of the table.

Theviewportmetatagensuresproperdisplayonmobiledevicesbysettingwidth=device-widthandinitial-scale=1.0,preventingtiny,unreadablecontentandenablingresponsivedesignforbetterusabilityacrossscreens.

Useinputtype="email"tocreateanemailfieldwithbuilt-invalidation,properformatting,andmobilekeyboardsupport;includename,id,placeholder,andrequiredattributesforaccessibilityandfunctionality.
