|
| 1 | +# Links |
| 2 | +Links are a crucial part of the internet. They do exactly as their name sounds. They allow us to navigate and connect to other web pages. |
| 3 | + |
| 4 | +# The Simplest Link |
| 5 | +```html |
| 6 | +<a href="somewebsite.com">Website Name</a> |
| 7 | +``` |
| 8 | +To create a link, we use the *a* tag. The *a* stands for anchor. You'll notice that the anchor tag has a *href* attribute. This stands for hyper reference. This is where you would put the web page you are linking to. |
| 9 | +For example: |
| 10 | +```html |
| 11 | +<a href="https://www.webuildblack.com">We Build Black</a> |
| 12 | +``` |
| 13 | +This renders to this: |
| 14 | + |
| 15 | + |
| 16 | +## Global and Relative Links |
| 17 | +Links are actually something called URLs (Uniform Resource Locator), and we can type them in two ways. |
| 18 | + |
| 19 | +### Global Links |
| 20 | +Global links refer ot the absolute location of a page. They start with a protocol (usually *http* or *https*), then the domain name (ex:webuildblack.com). Here are some examples of global links: |
| 21 | +* *https://colorforcode.com/* |
| 22 | +* *https://www.youtube.com/channel/UC4ZjOw_KACO5GSa2ShDuv3Q* |
| 23 | +* *https://etsy.com/* |
| 24 | + |
| 25 | +### Relative Links |
| 26 | +Relative links point to places on the computer's current system. So think if it as "relative to where you are" links. For example: |
| 27 | +* *./images/elephants.jpg* - This is a URL to an image in the same directory as the current page (the './' is optional) |
| 28 | +* *../all-images/* - The two dots (..) means to up to the parent directory. Then it says go into another directory in the parent called 'all-images'. |
| 29 | +* */documentation* - The forwards slash (/) at the beginning means go to the top of the project. After going to the top of the project, we go into a folder called "documentation" |
| 30 | + |
| 31 | +## Linking inside a page |
| 32 | +You can actually link to parts of a page. For example, you can put an *id* attribute on a tag like this: |
| 33 | +```html |
| 34 | +<button id="buy-button">Click me!</button> |
| 35 | +``` |
| 36 | +Then to link to it, we create an anchor tag with the *href* value the same at the buttons *id* value. |
| 37 | +```html |
| 38 | +<a href="buy-button">I go the buy button</button> |
| 39 | +``` |
| 40 | +Now, if you click on the anchor tag it will snap your screen to where the buy button is. We'll go deeper into the *id* attribute in the CSS lessons. It's actually really important. |
| 41 | + |
| 42 | +## Email Links |
| 43 | +Have you ever clicked an email address on a web page, and your computer automatically opened your email application with a draft to the address you just clicked on? That was an email link and you create them as so: |
| 44 | +```html |
| 45 | +< a href= "mailto:[email protected]">Say hi!</ a> |
| 46 | +``` |
| 47 | + |
| 48 | +## Link titles |
| 49 | +Link titles are the messages you see when hovering your mouse over a link. To set a title for a link you must use the *title* attribute. For example: |
| 50 | +```html |
| 51 | +<a href="https://www.webuildblack.com" title="A Community for Black Technologists">Check us out</a> |
| 52 | +``` |
| 53 | +Put this in your HTML doc and hover the link. You should see that message pop up. |
| 54 | + |
| 55 | +## Stick around for the next episode... |
| 56 | +In the next lesson, we'll be getting pretty with images. Our pages are gonna start looking a lil more lively. Don't worry, you'll be done with your karate drills soon :) |
0 commit comments