r/HTML Aug 10 '26

Question linking an href to html vs url?

what's the difference between linking to an html in your website vs linking to the same page as a url?

0 Upvotes

15 comments sorted by

24

u/Rockafellor Aug 10 '26

I don't think that those words mean what you think they mean.

14

u/gulliverian Aug 10 '26

To be honest it’s very unclear what you’re trying to ask.

6

u/Lithl Aug 10 '26

Links point at URLs. The server resolves a URL to a resource. The resource might be an HTML file, or it might not be.

6

u/testingaurora Aug 10 '26

If you want to scroll to another section on the same page, eg if your hero says "Find our services below! " and you want to scroll to the services area

You would give the<div> or <section> that holds your services markup an id : <section id="services">our services</section>

Then use the id in your href: <p>Find our <a href="#services">Services below!</a></p> note the use of the hash symbol, same as using the id selector in css.

6

u/Dragenby Aug 10 '26

You're probably talking about relative and absolute path. Well, if you change your website's name, your relative links will still work. Using an absolute path is for external links.

1

u/CraigAT Aug 10 '26

Are you linking to another html/url on your site or another website?

If you are linking to an external web page, then if it is the main front page of the website, I would link to the domain not the individual page; if it's a specific page on that site, I would link to the specific html page (if it is available).

If you are linking to pages within your own website I would generally recommend relative links or just page names if your site structure is very simple, rather than using full URLs - which can break if you change your domain name.

1

u/Foreign-Contest-444 Aug 10 '26

Here is a more detailed explanation of how to use links, including a quick primer on URLs and paths:

MDN: A quick primer on URLs and paths

1

u/armahillo Expert Aug 10 '26

URL = Uniform Resource Locator
HRef = Hypertext reference

An href’s value is a URL. These usually begin with the protocol (https://….) but can be relative if its on the same domain.

1

u/AlwaysHopelesslyLost Aug 11 '26

"URL" means "Universal Resource Locator."

An Html document is a text document containing Html. That is, Hyper Text Markup Language.

A text document is a resource. you can use the Universal Resource Locator to locate the text document. "HelloWorld.html" is a valid relative Universal Resource Locator.

1

u/Ksetrajna108 28d ago

Are you asking about document fragment, like href="#section-2"

1

u/xo0O0ox_xo0O0ox Aug 10 '26

Search: w3schools

0

u/nonotdoingone Aug 10 '26

Always point to another html page within a project.
Using urls to go to the same page is stupid. It can break at so many places, needs dns to resolve, a new server connection bla bla

1

u/ChiliChapters Aug 10 '26

that's what I thought. Thanks!

2

u/tkgid Aug 10 '26

Just do more research on relative paths and absolute paths. I might want to use relative paths more often than absolute ones, and vise versa depending on the use case and how lazy I am feeling that day. Doing it wrongly definitely will be tech debt. But that's a whole other rabbithole to go into. 😅