|
| 1 | +## Step 4: Add an image |
| 2 | + |
| 3 | +Let's learn how to include [images in markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#images), using relative urls, absolute urls, sizing, and basic positioning. |
| 4 | + |
| 5 | +### Regular Markdown |
| 6 | + |
| 7 | +Images can be displayed by providing a relative URL to a file in the repository or an absolute URL (to anywhere on the internet). |
| 8 | + |
| 9 | +The descriptive text in the square brackets is displayed if the image is unable to load, and it is also read aloud for people using screen readers. |
| 10 | + |
| 11 | +Note: Markdown syntax doesn't provide an option to change the image size. |
| 12 | + |
| 13 | +### Example |
| 14 | + |
| 15 | +Relative URL to an image in the repository: |
| 16 | +```md |
| 17 | + |
| 18 | + |
| 19 | +``` |
| 20 | + |
| 21 | +Absolute URL to an image on the internet: |
| 22 | +```md |
| 23 | + |
| 24 | +``` |
| 25 | + |
| 26 | +<img alt="Mona the Octocat" src="https://octodex.github.com/images/original.png" width="200"> |
| 27 | + |
| 28 | +### Simple HTML |
| 29 | + |
| 30 | +You will often find the need to reduce the size of an image or simply place it next to some text. Regular HTML syntax provides some additional flexibility. |
| 31 | + |
| 32 | +- The `alt` field specifies the alternative text. |
| 33 | +- The `src` field specifies the source url of the image. |
| 34 | +- A `width` and/or `height` field can be used to specify the size in pixels. |
| 35 | +- The `align` field allows setting a position (`left`, `right`) |
| 36 | + |
| 37 | +```md |
| 38 | +<img alt="Mona the Octocat" src="https://octodex.github.com/images/original.png" |
| 39 | +width="200" align="right"> |
| 40 | +``` |
| 41 | + |
| 42 | +### :keyboard: Activity: Add some decoration |
| 43 | + |
| 44 | +Our blog post is quite simple right now. Let's add some decoration. |
| 45 | + |
| 46 | +1. On the `start-blog` branch, open the `day-1.md` file for editing. |
| 47 | + |
| 48 | +1. Insert an image below the **Morning Planning** level 1 heading. |
| 49 | + |
| 50 | + ```md |
| 51 | +  |
| 52 | + ``` |
| 53 | + |
| 54 | +1. Use the **Preview** tab to check your Markdown formatting. |
| 55 | + |
| 56 | + - Notice the image is too large for our purpose. |
| 57 | + |
| 58 | +1. Replace the simple markdown version with an HTML version that includes size and position info. Much better! |
| 59 | + |
| 60 | + ```md |
| 61 | + <img alt="Cloudy morning" src="https://octodex.github.com/images/cloud.jpg" width="100" align="right"> |
| 62 | + ``` |
| 63 | + |
| 64 | +1. In the top right, click the **Commit changes** button and commit directly to the `start-blog` branch. |
| 65 | + |
| 66 | +1. With our image added and committed, Mona should be busy reviewing your work and preparing the next steps. |
| 67 | + |
| 68 | +<details> |
| 69 | +<summary>Having trouble? 🤷</summary><br/> |
| 70 | + |
| 71 | +- Confirm you are editing the correct file and branch. |
| 72 | +- Double check your syntax. An HTML image tag must start with `img` and include the `src` property. |
| 73 | + |
| 74 | +</details> |
0 commit comments