# HTML Links and Images

Links allow users to navigate between pages and websites.

Images can be used to display photos, logos and graphics on a webpage.

---

## Creating a Link

Use the `a` element to create a hyperlink.

```html
<a href="page.html">Go to Page</a>
```

Result:

<a href="#">Go to Page</a>

When clicked, the browser will open the specified page.

---

## Linking to Another Website

Use a full web address when linking to an external website.

```html
<a href="https://www.google.com">
    Visit Google
</a>
```

Result:

<a href="https://www.google.com">Visit Google</a>

---

## Opening a Link in a New Tab

Add the `target="_blank"` attribute.

```html
<a href="https://www.google.com"
   target="_blank"
   rel="noopener noreferrer">

    Visit Google

</a>
```

Result:

<a href="https://www.google.com" target="_blank">Visit Google</a>

The `rel` attribute improves security when opening new tabs.

---

## Linking to an Email Address

Use the `mailto:` protocol.

```html
<a href="mailto:teacher@school.com">
    Email Teacher
</a>
```

Result:

<a href="mailto:teacher@school.com">Email Teacher</a>

When clicked, the user's email program will open.

---

## Creating an Image

Use the `img` element.

```html
<img src="images/dog.jpg"
     alt="Photo of a dog">
```

The `src` attribute specifies the image location.

The `alt` attribute provides alternative text if the image cannot be displayed.



![Photo of a Dog](https://mr.napper.au/uploads/images/gallery/2026-06/dog.jpg)

---

## Setting Image Width

Use the `width` attribute.

```html
<img src="images/dog.jpg"
     width="100"
     alt="Photo of a dog">
```

The image will be displayed at 100 pixels wide.

<img src="https://mr.napper.au/uploads/images/gallery/2026-06/dog.jpg"
     alt="Photo of a Dog"
     width="100">

## Responsive Images

A responsive image automatically scales to fit different screen sizes.

```html
<img src="images/dog.jpg"
     style="max-width:100%;"
     alt="Photo of a dog">
```

This is useful for:

- Phones
- Tablets
- Laptops
- Desktop computers

---

## Using an Image as a Link

Images can also be used as buttons.

```html
<a href="dogs.html">

    <img src="images/dog.jpg"
         alt="Dog">

</a>
```

When the image is clicked, the browser will open the specified page.

<a href="dogs.html">
<img src="https://mr.napper.au/uploads/images/gallery/2026-06/dog.jpg" alt="Dog">
</a>

---

## Displaying a Logo

A common use of images is displaying a website logo.

```html
<img src="images/logo.png"
     width="200"
     alt="Company Logo">
```

---

## Creating an Image Gallery

Multiple images can be displayed together.

```html
<img src="images/dog1.jpg"
     width="200"
     alt="Dog 1">

<img src="images/dog2.jpg"
     width="200"
     alt="Dog 2">

<img src="images/dog3.jpg"
     width="200"
     alt="Dog 3">
```

---

## Complete Example

```html
<!DOCTYPE html>

<html>

<head>
    <title>Links and Images</title>
</head>

<body>

    <h1>Links and Images</h1>

    <a href="page.html">
        Internal Page
    </a>

    <br><br>

    <a href="https://www.google.com"
       target="_blank"
       rel="noopener noreferrer">

        Google

    </a>

    <br><br>

    <a href="mailto:teacher@school.com">
        Email Teacher
    </a>

    <br><br>

    <img src="images/dog.jpg"
         width="300"
         alt="Photo of a dog">

</body>

</html>
```

---

## Quick Reference

### Internal Link

```html
<a href="page.html">
```

### External Link

```html
<a href="https://website.com">
```

### New Tab

```html
target="_blank"
```

### Email Link

```html
<a href="mailto:someone@email.com">
```

### Image

```html
<img src="image.jpg"
     alt="Description">
```

### Image Width

```html
width="300"
```

### Responsive Image

```html
style="max-width:100%;"
```

### Image Link

```html
<a href="page.html">

    <img src="image.jpg">

</a>
```

You now know how to create hyperlinks and display images in HTML.

Next tutorial: **HTML Lists and Tables**