Markdown: Markdown Image Syntax and Alt Text

A picture is worth a thousand words—in Markdown, inserting an image takes just one line of syntax, but doing it well takes a bit of know-how.

1. What You'll Learn


2. A Tech Blogger's Real Story

(1) Pain Point: Images That Won't Load

James runs a tech blog and includes several screenshots per article. At first he hosted images on his own server, but links kept breaking—the server migrated a few times and all the old links went dead. Worse, his image filenames were in Chinese, which some browsers couldn't load. Readers complained about "broken images," and the bounce rate spiked to 70%.

(2) Solution: Use an Image CDN and Naming Conventions

James migrated all images to a CDN-based image hosting service (like Cloudinary), switched to English filenames, and wrote descriptive Alt text for every image. He also used reference-style images in Markdown to centrally manage all URLs. After the switch, image load times improved by 3x and the bounce rate dropped to 35%.


3. Image Syntax Basics

(1) Inline Images

Image syntax is very similar to links, with just an extra ! in front:

MARKDOWN
![Alt Text](Image URL)

![Markdown Logo](https://markdown-here.com/img/icon256.png)
Part Description Example
![Alt Text] Text shown when image fails to load ![Screenshot]
(Image URL) The image file address (https://example.com/img/logo.png)

(2) Adjusting Image Size

Standard Markdown doesn't support setting image dimensions. Use the HTML <img> tag when needed:

MARKDOWN
![Default Insert](logo.png)

<img src="logo.png" width="200" alt="Set width to 200px">
💡 Tip: In 90% of cases, standard Markdown image syntax is all you need. Fall back to HTML <img> only when you actually need size control.

▶ Example: Inserting a Local Image

MARKDOWN
![Project Architecture Diagram](./assets/architecture.png)

![Screenshot: Login Page](../screenshots/login-page.png)
💡 Tip: Good Alt text should describe both the content and function of the image. For decorative images (like separator icons), Alt text can be empty ![] but should never be omitted entirely.


(1) Clickable Images

Wrap an image inside link syntax to make it clickable:

MARKDOWN
[![Click to Enlarge](thumbnail.jpg)](fullsize-image.jpg)

[![Visit Website](logo.png)](https://example.com)

Structure breakdown:

MARKDOWN
[                          ← Link starts
  ![Thumbnail](thumbnail.jpg)  ← Image (clickable area)
]                          ← Link ends
(https://example.com)      ← Navigation target
MARKDOWN
## Project Badges

[![Build Status](https://img.shields.io/github/actions/workflow/status/user/repo/ci.yml)](https://github.com/user/repo/actions)
[![npm Version](https://img.shields.io/npm/v/package-name)](https://www.npmjs.com/package/package-name)

## Product Screenshots

| Feature | Screenshot |
|:-----|:-----|
| Dashboard | [![Dashboard Thumbnail](img/dashboard-thumb.png)](img/dashboard-full.png) |
| Settings | [![Settings Thumbnail](img/settings-thumb.png)](img/settings-full.png) |
💡 Tip: This is the common "Badge" pattern seen in GitHub READMEs. Clicking a badge navigates to the corresponding service (e.g., CI status page, npm package page).


6. Reference Images

Like reference links, image URLs can be centrally managed:

MARKDOWN
In the body:
![Company Logo][logo]
![Product Screenshot][screenshot1]

Defined at the bottom:
[logo]: https://cdn.example.com/logo.png "Company Logo"
[screenshot1]: https://cdn.example.com/screenshots/v2/dashboard.png "New Dashboard Screenshot"
💡 Tip: Reference images are especially useful for maintaining large documentation sets. When migrating to a new image host, you only need to update the URL definitions at the bottom.


7. Image Best Practices

(1) Choosing File Formats

Format Best For Pros Cons
PNG Screenshots, icons, transparent backgrounds Lossless, high quality Large file size
JPEG Photos, complex color images Small file size Lossy compression
SVG Icons, logos, illustrations Infinitely scalable, tiny files Not for photos
GIF Simple animations Great compatibility Limited colors, large files
WebP Replace PNG/JPEG 25-35% smaller Some older browsers unsupported

(2) Image Optimization Tips

MARKDOWN
1. Control size: keep individual images under 500KB, aim for 100-300KB
2. Use a CDN: accelerate global loading
3. English filenames: logo.png ✅ lo#go.png ❌
4. Logical directories: assets/images/ or img/
5. Write Alt text: every image must have descriptive Alt text
⚠️ Note: In GitHub READMEs, referencing local image paths (./assets/image.png) is safe, but if you reference an external image host, make sure the service is stable and reliable.

▶ Example: Images in a Product Documentation

MARKDOWN
## UI Showcase

### Login Page

![Login page screenshot showing email and password fields with "Remember me" option](img/login-page.png)

### Dashboard

![Dashboard interface showing 6 left sidebar navigation items and central data overview cards](img/dashboard-overview.png)

> **Note:** Click the image to view the full-resolution version
[![Dashboard Thumbnail](img/dashboard-thumb.png)](img/dashboard-full.png)

8. Complete Example: Image Showcase in a Project README

TEXT 📖 Display only
Awesome App README Structure:

Title line: # Awesome App + badge images
Screenshot table: Mobile | Desktop
Install command: npm install awesome-app
Logo reference: [logo]: https://cdn.example.com/logo.png

Expected result: A visually rich GitHub README with a project banner, badges, a screenshot showcase, and a centrally managed Logo defined at the end of the document.


❓ FAQ

Q My image is too large—how do I shrink it in Markdown?
A Standard Markdown doesn't support size control. Use HTML: <img src="url" width="400" alt="description">.
Q How do I write image paths on GitHub?
A Use relative paths like ./assets/image.png for images inside the repo. You can also use absolute URLs for external image hosting.
Q Can I use animated GIFs?
A Yes. The syntax is identical to static images. But watch the file size—a large GIF can be 5-10MB and slow down page loading.
Q What's the maximum length for Alt text?
A There's no hard limit, but 125 characters or fewer is recommended. Screen readers typically truncate overly long Alt text.
Q How do I use SVG icons?
A Reference the .svg file directly in Markdown. You can also embed SVG source code in Markdown (supported by some parsers).

📖 Summary


📝 Exercises

  1. Basic: Insert an image in Markdown (any online or local image) with descriptive Alt text. Then disable image loading in your browser to verify that the Alt text displays correctly.

  2. Intermediate: Create a small project where the README.md features a "click thumbnail to view full image" setup—the page shows small images, and clicking them opens the full-size version in a new tab.

  3. Challenge: Maintain a "Website Screenshot Gallery" using reference-style images with at least 5 screenshots and URLs defined at the bottom of the document. Then try converting those screenshots to WebP format and compare the file size difference.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏