htmlbroken-links

Why HTML hyperlink is not working in my sub folder?


I have created sub-folder "Pages" in my root directory and create "News.html" inside it .In this html file, i create hyperlink refer to root directory but when i click on link Nothing Happens instead of opening index.html page.

Here is my code:

<!DOCTYPE html>
<html>

<head>


<title>web page</title>


</head>

<body>


<h1>This is News Page</h1>

<a href = "\index.html">Index</a>

</body>

</html>

I know alternatively this can work:

<a href = "../index.html">Index</a>   <!- ../ to target a parent folder

But why referring back to directory cannot work?


Solution

  • you can use just the code below to target a parent folder's file

    <a href = "../index.html">Index</a>   <!- ../ to target a parent folder -->
    

    note : if you use live server from visual studio code that won't work because of security problems and access limitation hope it helps !