Keywords: Jekyll | Markdown | Image Captions | HTML Semantics | GitHub Pages
Abstract: This technical paper comprehensively examines three primary methods for adding image captions in Jekyll Markdown blogs: direct HTML figure tag embedding, reusable component implementation through Jekyll include templates, and lightweight solutions using CSS selectors with emphasis tags. The analysis covers advantages and limitations of each approach, provides complete code examples with implementation details, and emphasizes semantic HTML importance along with GitHub Pages compatibility considerations.
Introduction
In technical blogging with Jekyll and Markdown, images serve as essential visual elements. However, the standard Markdown syntax  only supports basic image embedding without native caption capabilities. Based on Stack Overflow community best practices, this paper systematically explores three effective approaches for implementing image captions in Jekyll Markdown.
Method 1: Direct HTML Figure Tag Embedding
The most semantically appropriate approach involves directly using HTML5's <figure> and <figcaption> tags. This method fully adheres to web standards, ensuring excellent accessibility and SEO performance.
<figure>
<img src="{{site.url}}/assets/image.jpg" alt="Image description text"/>
<figcaption>This is the image caption text</figcaption>
</figure>
The Markdown specification explicitly permits direct HTML embedding within documents, making this approach work perfectly in Jekyll. Key advantages include:
- Semantic integrity: Proper use of HTML5 semantic tags
- Dependency-free: No additional plugins or configuration required
- Style control: Precise caption styling through CSS
Method 2: Jekyll Include Template Approach
For scenarios requiring frequent image caption addition, creating reusable Jekyll include templates provides a more elegant solution. This method is particularly suitable for maintaining large blogs or projects requiring unified image styling.
First, create an image.html file in the _includes directory:
<figure class="image">
<img src="{{ include.url }}" alt="{{ include.description }}">
<figcaption>{{ include.description }}</figcaption>
</figure>
Then invoke via Liquid tags in Markdown files:
{% include image.html url="/images/my-cat.jpg" description="My cat, Robert Downey Jr." %}
Notable advantages of this method include:
- Code reuse: Define once, use multiple times
- Easy maintenance: Global updates through template modification
- GitHub Pages compatibility: Deployment without pre-generation
- Parameterization: Support for dynamic image URL and description passing
Method 3: CSS Selector with Emphasis Tag Combination
For simple caption requirements, a lightweight CSS selector approach can be employed. This method achieves caption effects by immediately following images with emphasis tags.
Write in Markdown:

*Image caption text*
Crucial note: No blank lines between image and caption, otherwise they parse as separate paragraphs. Generated HTML structure:
<p>
<img src="path_to_image" alt>
<em>Image caption text</em>
</p>
Style control through CSS selector:
img + em {
display: block;
font-style: italic;
text-align: center;
font-size: 0.9em;
color: #666;
margin-top: 0.5em;
}
Style Customization and Advanced Features
The referenced article's Kramdown extension syntax demonstrates more complex image style control. For example, combining with Bootstrap responsive classes:
{: style="float: right; height: 65%; width: 65%; margin-left: 1em; margin-top: 2em;"}{:class="img-responsive"}
For caption styling, <sup> tags can achieve superscript effects, or specialized caption classes can be defined via CSS:
.image-caption {
font-size: 0.8em;
font-style: italic;
text-align: center;
color: #888;
}
Compatibility Considerations and Best Practices
When selecting implementation approaches, consider these factors:
- GitHub Pages limitations: Avoid plugins requiring preprocessing, ensure direct push deployment
- Semantic priority: Prefer
<figure>and<figcaption>for optimal accessibility - Maintenance cost: Include template method更适合 long-term maintenance in large projects
- Style consistency: Ensure visual consistency across sites through unified CSS class names
Conclusion
This paper systematically introduces three primary methods for implementing image captions in Jekyll Markdown. Direct HTML embedding suits occasional use cases, Jekyll include templates fit highly reusable projects, while CSS selector approaches provide the lightest implementation. Developers should choose the most appropriate method based on specific requirements while consistently prioritizing semantic HTML and accessibility considerations.