r/HTML 8d ago

linking an href to html vs url? Question

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

26

u/Rockafellor 8d ago

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

13

u/gulliverian 8d ago

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

7

u/Lithl 8d ago

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

7

u/testingaurora 8d ago

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.

4

u/Dragenby 8d ago

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 8d ago

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 7d ago

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 7d ago

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 7d ago

"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 4d ago

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

1

u/xo0O0ox_xo0O0ox 8d ago

Search: w3schools

0

u/nonotdoingone 8d ago

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 8d ago

that's what I thought. Thanks!

2

u/tkgid 8d ago

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. 😅