Href="#" for image linking

Tell us what’s happening:
I’m a beginner, and just trying to understand some logic here. In this tutorial the correct response to linking an image is to use href="#"< img…etc.

In the previous lesson however, it says to use href="#" when you don’t know where your link will lead to. Why do we use href="#" before img src when turning an image into a link?

   **Your code so far**

<h2>CatPhotoApp</h2>
<main>
 <p>Click here to view more <a href="#">cat photos</a>.</p>

<a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>

 <p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
 <p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>
   **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36

Challenge: Turn an Image into a Link

Link to the challenge:

use href="#"

<a> anchor tag is a hyperlink, when clicked they take you somewhere.
if you have nowhere in mind <a href="#"></a> will take you to the top of the page.

here are a article about this and question in stackoverflow about this:

What is a Hyperlink? Definition for HTML Link Beginners (freecodecamp.org)

html - What is href="#" and why is it used? - Stack Overflow

You need to think of it as if the whole anchor element with href="#" is wrapped around the image. The exercise tells you to make the image clickable by providing a link so that when you click on the image, you’re led to the given href.

It won’t work if you don’t wrap the anchor element with the link around the image.

Try this:

<img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."><a href="#"></a>

You’ll see that the anchor element doesn’t do anything. It’s not wrapped around content whatsoever so there’s nothing to click on.

Let me know if you need some more explanation

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