So I just started learning HTML and I wanted to start my first basic project. I am creating a website that allows the user to learn about the different coding languages. The home page is basic as of now, but it includes a link to learn more about HTML. However, that link does not work. I used <a href>
and have it saved as a local file in the same folder as the home page, but on Chrome, it says, "Your file couldn’t be accessed". I included screenshots of the message, files, and the code itself.
I am wanting the HTML link to bring me to my second file of code that explains what HTML is.
codes for link to HTML page:
<a href="/html.html>HTML</a>
Code for gong back to coding page:
<a href="/coding.html>BACK</a>
5
Answers
Try to remove ‘/’ in href
if both html files are in the same folder
You need to remove the
/
before the file name.You tried to remove the bar, the bar took you to the root, that is, to c:
using only
/
is pointing to the absolute root directory where in your case it isC:
drive in your computer regardless of the directory you used (desktop or any other directory in C drive).You need to use
./
to point to the base url where by default it is the current directory if you have not defined base url in the header.Or you may omit / and set only
html.html
orcoding.html
as href value if you didn’t set base url in your document and all files are in a same directorythe problem in your code is that your setting your href path to "/code.html", this will send you to the root of wherever you’re loading your file (In this case, the root of your C: disk).
What you want in this case is to use relative paths, which take as a starting point, the root of your project (HTML Project 1).
You can use as some other comments says just "code.html" and it will infeer the relative path but it would be better to use "./" as it is what indicates the path is actually relative at the begining, specially if you’ll work in the future with more folders for your routing.
so for your code, you’ll have "./code.html"