Nav bar links

Hi guys not sure if you can see the image. But my problem is that I cant get my links in the nav bar to actually link to the pages. The links are showing under the nav bar and it says page not found

Do you have the pages [files] default.asp and projects.asp and so on
in the same directory [folder] ?

I dont think so? How do i create a folder? Sorry really new to this!

You don’t need another folder, but you need to create the appropriate files.
If its a Codecademy workspace, then, close to the top left, there’s a + button that lets you create/add a file.

Woo thats very flash! Thanks


do i just put a <a href=“link here” type thing in?

yes, you can;
but you’ll probably want another webpage file (like the html file or .asp file you mentioned) too.

Kia Ora,

I’m not sure what you’re trying to do exactly… are you intending for those links to bring the user to the different sections of your page? If so, take a look at this code:

<!DOCTYPE html>
<html>
    <head>
        <title>Sophie Napier</title>
        <link href="style.css" rel="stylesheet">
    </head>

    <body>
        <div class="nav">
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="./projects.html">Projects</a></li>
                <li><a href="#contact">Contact</a></li>
                <li><a href="#about">About</a></li>
            </ul>
        </div>

        <div class="main-content">
            <h1>Hello friends!</h1>
            <p>This is my first website.</p>

            <h2 id="about">About Me</h2>
            <p>I studied a bachelor of...</p>

            <h2 id="contact">Contact</h2>
            <p>My LinkedIn details are...</p>
        </div>
    </body>
</html>

In the nav section, you’ll see three different types of link:

  • <a href="#"> just links back to the top of the current page.

  • <a href="./projects.html"> is a link to another file within the same directory as your current one.

  • both <a href="#contact"> and <a href="#about"> will bring you to those sections on the current page. But in order for these links to work, you have to give the corresponding sections the same id, as in <h2 id="contact">, and <h2 id="about">.

I hope this helps a little ?

Happy coding :slight_smile:

Trying to link to a different page on the same website. So do I use ./projects.html?

Well that didnt work :joy:

Have you created a portfolio.html file and placed it in the same folder as index.html? In the screen capture image above, I can see that you have three files in the ‘Projects’ folder, index.html, script.js, and style.css. You will need to add portfolio.html, and then the link should work.

As an aside, if ./portfolio.html doesn’t work, try just portfolio.html instead. They should both point to the current directory.

It’s nice to see another resident of Aotearoa on the Codecademy forums, by the way! :slight_smile:

Create html file and save it. Then you can download it from of your choice of game or app

:smiley: I have realised I can actually share code link! LOL I’m a spoon
https://www.codecademy.com/workspaces/630935997b93e12c7b97a1fa

1 Like

if you want <a href="#about-me">About me</a> to link to something else on the the same page, then you have to have an element that has the attribute id="about-me" somewhere else in the webpage
(that’s what would be linked to)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.