Sub topic 5
Links and images
This chapter assumes you can edit a Markdown file on GitHub and know basic heading and paragraph syntax. Links and images share one pattern. An image is a link with a leading !.
Inline links
An inline link puts the visible text in square brackets and the destination in parentheses right after it. No space may sit between the two.
Read the [contributing guide](CONTRIBUTING.md) before opening a pull request.
Visit [GitHub Docs](https://docs.github.com "Official documentation").The optional quoted text after the URL is a title. Browsers show it as a tooltip. Write link text that makes sense out of context. "Contributing guide" works. "Click here" does not.
Reference links
If a URL appears several times or clutters a sentence, define it once and refer to it by label. Labels are not case-sensitive. The definition can go anywhere in the file, and it does not appear in the rendered page.
See the [API reference][api] and the [changelog][changes].
The [API reference][api] also lists error codes.
[api]: https://example.com/docs/api
[changes]: CHANGELOG.mdImages
An image starts with !. The text in brackets is the alt text. Screen readers read it aloud, and GitHub shows it if the file fails to load.
An image can also be a link. Wrap the whole image syntax in link brackets.
[](https://example.com)How GitHub resolves a destination
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Link shows as plain text | Space between `]` and `(` | Remove the space |
| Link breaks partway through | Space or `)` inside the URL | Replace a space with `%20`, or a `)` with `%29` |
| Image shows as a broken icon | Wrong path or wrong letter case | Check the path against the repository tree |
| Image appears as a link, not a picture | Missing `!` | Add `!` before the bracket |
| Link goes to the wrong site | Missing `https://` | Write the full address |
For the image rows, check the path first. Most broken images come from a path written relative to the wrong folder.
Exercise
A README at the repository root contains . The file in the repository is named assets/demo.gif. The image does not display. Give two problems with this line and a corrected version.
Show answer
The letter case of the filename does not match, and the alt text is empty. Corrected: .