Set the image size in markdown syntax
Controlling Image Size in Markdown
Standard Markdown syntax doesn’t include built-in parameters for image dimensions. The basic syntax  produces images at their original size or constrained by container width, with no way to specify explicit dimensions.
If you need to control image size, you have several options depending on your use case and platform.
HTML <img> Tag
The most direct approach is using HTML directly within your Markdown document:
<img src="http://example.com/img.png" alt="img text" width="400" height="300" />
This works universally across Markdown processors and gives you full control. Specify dimensions in pixels, or use percentage values for responsive layouts:
<img src="http://example.com/img.png" alt="img text" width="80%" />
Markdown Extensions
Many Markdown flavors support extended syntax for sizing. Check what your platform uses:
Kramdown (Jekyll, GitHub Pages):
{:width="400px" height="300px"}
Pandoc:
{width=400 height=300}
MultiMarkdown:
![alt text][image]
[image]: http://example.com/img.png "title" {width=400px height=300px}
HTML with CSS Classes
For styling consistency across multiple images, use HTML with class attributes:
<img src="http://example.com/img.png" alt="img text" class="thumbnail" />
Then define in your CSS:
img.thumbnail {
width: 200px;
height: auto;
}
Picture Element for Responsive Images
If you’re building modern web content, use the HTML <picture> element for responsive images:
<picture>
<source media="(min-width: 768px)" srcset="large-image.png">
<source media="(min-width: 480px)" srcset="medium-image.png">
<img src="small-image.png" alt="descriptive text" style="width: 100%; height: auto;">
</picture>
This approach loads different image sizes based on device width, improving performance and user experience.
Practical Considerations
- Aspect ratio: Use
widthandheightattributes together, or set one dimension and useheight: autoin CSS to maintain aspect ratio - Responsive design: Avoid fixed pixel dimensions on fluid layouts; prefer percentage-based widths or CSS media queries
- Accessibility: Always include meaningful
alttext regardless of which method you use - Platform limitations: Check your Markdown processor’s documentation—not all support extensions equally
For static site generators like Jekyll or Hugo, check what Markdown library they use (kramdown, goldmark, etc.) to know which syntax extensions are available. For simple cases where you need one-off sizing, raw HTML remains the most portable solution.