Position Text Below Image in HTML & CSS Easily

In the world of web design, the placement of text and images is crucial for creating visually appealing and user-friendly layouts. One common requirement is positioning text below an image, a task that can be achieved with relative ease using HTML and CSS. This article will guide you through the process, providing a comprehensive understanding of the techniques involved and offering practical examples to ensure you can implement these methods effectively.
Understanding the Basics: HTML Structure

Before diving into CSS positioning, it’s essential to establish a solid HTML foundation. The basic structure for placing text below an image involves using semantic HTML elements to ensure accessibility and proper document outline.
<figure>
<img src="image.jpg" alt="Descriptive image text">
<figcaption>This is the text that will appear below the image.</figcaption>
</figure>
In this example:
- The <figure>
element is used to encapsulate the image and its caption, providing a semantic container for self-contained content.
- <img>
is the standard HTML tag for embedding images, with the src
attribute pointing to the image file and alt
providing alternative text for accessibility.
- <figcaption>
contains the text that will be positioned below the image.
CSS Positioning Techniques

1. Block-Level Elements and Normal Flow
The simplest way to position text below an image is by relying on the normal flow of block-level elements. In HTML, both <img>
and <figcaption>
are inherently block-level elements, meaning they naturally stack vertically.
figure {
margin: 0; /* Remove default figure margin */
}
img {
display: block; /* Ensure image is a block-level element */
width: 100%; /* Make image responsive */
height: auto; /* Maintain aspect ratio */
}
figcaption {
margin-top: 10px; /* Add space between image and text */
}
Key Points:
- Block-Level Behavior: By default, block-level elements like <img>
and <figcaption>
will stack vertically, placing the text below the image without additional CSS.
- Responsive Design: Setting width: 100%
and height: auto
ensures the image scales with its container, a fundamental aspect of responsive web design.
2. Flexbox Layout
For more control over alignment and spacing, Flexbox offers a powerful solution. This method is particularly useful when you need to center the image and text or adjust their vertical alignment.
figure {
display: flex;
flex-direction: column;
align-items: center; /* Center items horizontally */
text-align: center; /* Center text within figcaption */
}
img {
max-width: 100%; /* Ensure image doesn't overflow */
height: auto;
}
figcaption {
margin-top: 15px; /* Adjust spacing between image and text */
}
Flexbox Advantages:
- Vertical Stacking: flex-direction: column
ensures the image and text stack vertically.
- Centering: align-items: center
and text-align: center
center the content both horizontally and textually.
- Responsive Images: max-width: 100%
prevents images from overflowing their containers.
3. CSS Grid Layout
CSS Grid is another modern layout system that provides precise control over the placement of elements. While it might be overkill for simple text-below-image scenarios, it’s useful for more complex layouts.
figure {
display: grid;
grid-template-rows: auto 1fr; /* Image takes auto height, text takes remaining space */
gap: 10px; /* Space between image and text */
}
img {
width: 100%;
height: auto;
}
figcaption {
align-self: start; /* Align text to the top of the grid area */
}
Grid Layout Benefits:
- Explicit Rows: grid-template-rows
defines the structure, ensuring the image and text occupy separate rows.
- Gap Control: The gap
property simplifies spacing between elements.
- Alignment: align-self: start
ensures the text starts at the top of its grid area.
Advanced Techniques and Considerations
Responsive Design Enhancements
To ensure your layout works seamlessly across various devices, consider using relative units and media queries.
figcaption {
font-size: 1.2em; /* Relative font size */
margin-top: 1em; /* Relative margin */
}
@media (max-width: 600px) {
figcaption {
font-size: 1em; /* Adjust font size for smaller screens */
}
}
Responsive Best Practices:
- Relative Units: Use em
or rem
for font sizes and margins to maintain proportional relationships.
- Media Queries: Adapt styles for different screen sizes to optimize readability and layout.
Accessibility and SEO
When positioning text below images, it’s crucial to maintain accessibility and SEO best practices.
- Alternative Text: Always provide descriptive
alt
text for images to assist screen readers and improve SEO. - Semantic HTML: Use
<figure>
and<figcaption>
to ensure screen readers and search engines understand the relationship between the image and text.
Performance Optimization
Optimizing images is essential for fast-loading web pages. Consider the following:
- Image Formats: Use modern formats like WebP that offer better compression without quality loss.
- Lazy Loading: Implement lazy loading for images below the fold to improve initial page load times.
<img src="image.webp" alt="Descriptive image text" loading="lazy">
Performance Tips: - Compression Tools: Use tools like ImageOptim or Squoosh to compress images without sacrificing quality. - CDNs: Serve images from a Content Delivery Network (CDN) to reduce latency.
Practical Example: Building a Card Component
Let’s apply these techniques to create a card component where an image is followed by text, commonly used in blogs, product listings, and portfolios.
<div class="card">
<img src="card-image.jpg" alt="Card image description">
<div class="card-content">
<h2>Card Title</h2>
<p>This is the card's descriptive text, positioned below the image.</p>
</div>
</div>
.card {
display: flex;
flex-direction: column;
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
max-width: 300px;
margin: 20px;
}
.card img {
width: 100%;
height: auto;
}
.card-content {
padding: 15px;
text-align: center;
}
.card h2 {
margin: 0 0 10px;
}
.card p {
margin: 0;
}
Card Component Features: - Flexbox Layout: Ensures the image and content stack vertically. - Border and Padding: Adds visual separation and spacing. - Responsive Design: The card adjusts to different screen sizes while maintaining its structure.
Comparative Analysis: When to Use Each Method

Method | Best Use Case | Pros | Cons |
---|---|---|---|
Normal Flow | Simple layouts with minimal styling | No extra CSS needed, inherently accessible | Limited control over alignment and spacing |
Flexbox | Centering content, dynamic layouts | Easy alignment, responsive design | Requires understanding of Flexbox properties |
CSS Grid | Complex layouts with precise control | Explicit grid structure, gap control | Overkill for simple text-below-image scenarios |

FAQ Section
How do I ensure the text is always centered below the image?
+Use Flexbox with `align-items: center` and `text-align: center` to center both the image and text horizontally and textually.
Can I use these techniques for responsive design?
+Yes, by using relative units like `em` or `%` and media queries, you can ensure the layout adapts to different screen sizes.
div>What’s the best way to optimize images for web performance?
+Use modern formats like WebP, compress images with tools like ImageOptim, and implement lazy loading for images below the fold.
How do I maintain accessibility when positioning text below images?
+Always provide descriptive `alt` text for images and use semantic HTML elements like `
Is it better to use Flexbox or CSS Grid for this task?
+For simple text-below-image scenarios, Flexbox is often sufficient. CSS Grid is more suitable for complex layouts requiring precise control.
Conclusion
Positioning text below an image in HTML and CSS is a fundamental skill in web design, offering both functional and aesthetic benefits. By understanding the various techniques—from the simplicity of normal flow to the flexibility of Flexbox and the precision of CSS Grid—you can choose the best approach for your specific needs. Additionally, incorporating responsive design principles, accessibility best practices, and performance optimizations ensures your layouts are not only visually appealing but also user-friendly and efficient.
Whether you’re building a simple blog post, a complex e-commerce site, or a dynamic portfolio, mastering these techniques will empower you to create engaging and accessible web experiences. Remember, the key to effective web design lies in balancing aesthetics, functionality, and performance, and with the right tools and knowledge, you can achieve all three.