π§Ό Bootstrap 5 β Placeholders: Simulate Content While Loading
π§² Introduction β What Are Placeholders in Bootstrap 5?
Placeholders in Bootstrap 5 are utility classes used to show loading skeletons or fake content blocks while the real data is being fetched. They help maintain UI layout and improve user perception of performance by indicating that something is loading behind the scenes.
π― In this guide, youβll learn:
- How to create text, image, and block placeholders
- Use animations for shimmer effects
- Match placeholder styles with components like cards and tables
- Best practices for responsive and accessible placeholders
β Example 1 β Basic Text Placeholder
<p>
<span class="placeholder col-6"></span>
</p>
π Explanation:
Class | Purpose |
---|---|
.placeholder | Base class for all placeholders |
.col-6 | Sets width to 50% using Bootstrap grid |
β Example 2 β Animated Placeholders
<p class="placeholder-glow">
<span class="placeholder col-6"></span>
</p>
<p class="placeholder-wave">
<span class="placeholder col-6"></span>
</p>
Class | Animation Style |
---|---|
.placeholder-glow | Soft fade-in animation |
.placeholder-wave | Ripple or shimmer loading animation |
β Example 3 β Placeholder for Buttons
<a class="btn btn-primary disabled placeholder col-4" aria-disabled="true"></a>
- Use
.placeholder
on buttons with.disabled
to simulate UI buttons during loading.
β Example 4 β Placeholder Card Example
<div class="card" aria-hidden="true">
<img src="..." class="card-img-top" alt="..." />
<div class="card-body">
<h5 class="card-title placeholder-glow">
<span class="placeholder col-6"></span>
</h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-6"></span>
<span class="placeholder col-8"></span>
</p>
<a class="btn btn-primary disabled placeholder col-6" aria-disabled="true"></a>
</div>
</div>
π Use Case:
- Create complete loading cards before data (e.g., user profiles, product info) is ready.
- Use
aria-hidden="true"
to skip placeholder content for screen readers.
β Placeholder Colors
Use Bootstrapβs background utility classes:
<span class="placeholder col-12 bg-primary"></span>
<span class="placeholder col-12 bg-success"></span>
<span class="placeholder col-12 bg-warning"></span>
Class | Color |
---|---|
bg-primary | Blue |
bg-success | Green |
bg-warning | Yellow |
π οΈ Best Practices for Placeholders
Tip | Why It Helps |
---|---|
Use same layout as real content | Prevents layout shifts and jank |
Pair with animations | Gives visual feedback during loading |
Add aria-hidden="true" | Hides placeholder from screen readers |
Use matching component widths | Ensures alignment when real data loads in |
Replace with real content ASAP | Avoid excessive skeleton delays |
π Summary β Simulate Content Load with Bootstrap Placeholders
Bootstrap 5 placeholders are modern skeleton screens used to indicate that content is loading. They offer visual feedback and maintain layout structure, enhancing UX on slower connections or dynamic content apps.
π Key Takeaways:
- Use
.placeholder
classes to show loading UI blocks - Animate with
.placeholder-glow
or.placeholder-wave
- Combine with
.disabled
for buttons or cards - Hide from screen readers with
aria-hidden="true"
- Control widths using Bootstrap grid classes (e.g.,
col-6
,col-4
)
βοΈ Ideal for loading dashboards, cards, tables, and interactive content.
β FAQs β Bootstrap 5 Placeholders
β Whatβs the difference between glow and wave animations?
β
.placeholder-glow
fades softly, while .placeholder-wave
shows a ripple/shimmer effect.
β Can placeholders be used in buttons or navs?
β
Yes. Apply .placeholder
with .disabled
and appropriate sizing (col-*
).
β Are placeholders responsive?
β
Yes. Use Bootstrapβs grid classes to adjust width across breakpoints (e.g., col-sm-4
, col-md-6
).
β Do placeholders affect accessibility?
β
Use aria-hidden="true"
so screen readers skip them during loading.
Share Now :