2018-09-30 23:01:58 +01:00
---
id: bad87fee1348bd9aedf08816
title: Link to External Pages with Anchor Elements
challengeType: 0
videoUrl: 'https://scrimba.com/p/pVMPUv/c8EkncB'
2019-07-31 11:32:23 -07:00
forumTopicId: 18226
2021-01-13 03:31:00 +01:00
dashedName: link-to-external-pages-with-anchor-elements
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You can use `a` (*anchor*) elements to link to content outside of your web page.
`a` elements need a destination web address called an `href` attribute. They also need anchor text. Here's an example:
2021-03-19 00:24:09 +01:00
```html
2021-04-26 19:04:53 +02:00
<a href="https://www.freecodecamp.org">this links to freecodecamp.org</a>
2021-03-19 00:24:09 +01:00
```
2020-11-27 19:02:05 +01:00
2021-01-21 01:10:19 -07:00
Then your browser will display the text `this links to freecodecamp.org` as a link you can click. And that link will take you to the web address `https://www.freecodecamp.org` .
2020-11-27 19:02:05 +01:00
# --instructions--
2021-04-26 19:04:53 +02:00
Create an `a` element that links to `https://www.freecatphotoapp.com` and has "cat photos" as its anchor text.
2020-11-27 19:02:05 +01:00
# --hints--
2021-02-01 11:56:07 -08:00
Your `a` element should have the anchor text of `cat photos` .
2020-11-27 19:02:05 +01:00
```js
assert(/cat photos/gi.test($('a').text()));
```
2021-04-26 19:04:53 +02:00
You need an `a` element that links to `https://www.freecatphotoapp.com`
2020-11-27 19:02:05 +01:00
```js
2021-05-06 06:36:33 +02:00
assert(/^https?:\/\/(www\.)?freecatphotoapp\.com\/?$/i.test($('a').attr('href')));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your `a` element should have a closing tag.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
code.match(/<\/a>/g) &&
code.match(/<\/a>/g).length === code.match(/<a/g).length
);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
<h2>CatPhotoApp</h2>
<main>
2018-10-08 01:01:53 +01:00
2021-04-26 19:04:53 +02:00
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
<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>
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-04-22 02:07:05 -04:00
```html
<h2>CatPhotoApp</h2>
<main>
2021-04-26 19:04:53 +02:00
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
2019-04-22 02:07:05 -04:00
2021-04-26 19:04:53 +02:00
<a href="https://www.freecatphotoapp.com">cat photos</a>
2019-04-22 02:07:05 -04:00
<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>
2018-09-30 23:01:58 +01:00
```