Bird
Raised Fist0
Bootsrapmarkup~10 mins

Carousel captions in Bootsrap - Browser Rendering Trace

Choose your learning style10 modes available
Render Flow - Carousel captions
Load HTML with carousel structure
↓
Create carousel container element
↓
Create carousel items as children
↓
Add caption elements inside each item
↓
Apply Bootstrap CSS styles
↓
Initialize carousel JS behavior
↓
Render captions over images
↓
Handle slide transitions
The browser reads the HTML structure of the carousel, creates the container and items, then adds caption elements inside each item. Bootstrap CSS styles position captions over images. JavaScript controls slide transitions and updates caption visibility.
Render Steps - 4 Steps
Code Added:<div class="carousel-inner"> <div class="carousel-item active"> <img src="img1.jpg" class="d-block w-100" alt="..."> </div> </div>
Before
[Empty carousel container]

[ ]
→
After
[Carousel container]
  [carousel-inner]
    [carousel-item active]
      [Image: img1.jpg filling width]

[Image fills container width]
Adding the first carousel item with an image shows the image filling the carousel area.
🔧 Browser Action:Creates DOM nodes for carousel-inner and carousel-item, loads image, triggers layout and paint.
Code Sample
This code creates a Bootstrap carousel with two slides. Each slide has an image and a caption that appears centered near the bottom of the image with white text and a subtle shadow for readability.
Bootsrap
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="img1.jpg" class="d-block w-100" alt="...">
      <div class="carousel-caption d-none d-md-block">
        <h5>First slide label</h5>
        <p>Some representative placeholder content for the first slide.</p>
      </div>
    </div>
    <div class="carousel-item">
      <img src="img2.jpg" class="d-block w-100" alt="...">
      <div class="carousel-caption d-none d-md-block">
        <h5>Second slide label</h5>
        <p>Some representative placeholder content for the second slide.</p>
      </div>
    </div>
  </div>
</div>
Bootsrap
.carousel-caption {
  position: absolute;
  right: 15%;
  bottom: 20px;
  left: 15%;
  z-index: 10;
  padding-top: 20px;
  padding-bottom: 20px;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
Render Quiz - 3 Questions
Test your understanding
After step 2, where is the caption positioned relative to the image?
ABelow the image outside the carousel
BAbove the image pushing it down
CCentered horizontally near the bottom of the image
DHidden and not visible
Common Confusions - 3 Topics
Why don't I see captions on small screens?
The caption uses classes 'd-none d-md-block' which hide captions on small screens and show them on medium and larger screens. This is to avoid clutter on small devices.
💡 Captions appear only on medium (md) and larger screens due to Bootstrap's responsive display classes.
Why does the caption text appear over the image and not push it down?
The caption uses 'position: absolute' which removes it from normal flow and overlays it on top of the image without affecting layout.
💡 Absolute positioning overlays captions on images without shifting other content.
Why does only one slide show at a time?
Bootstrap carousel shows one 'carousel-item' with class 'active' and hides others. Only the active slide and its caption are visible.
💡 Only the active slide and its caption are visible; others are hidden offscreen.
Property Reference
PropertyValue AppliedVisual EffectCommon Use
positionabsolutePositions caption over image relative to carousel itemOverlay captions on images
bottom20pxPlaces caption near bottom edge of imageVertical caption placement
left15%Indents caption from left edgeHorizontal caption centering
right15%Indents caption from right edgeHorizontal caption centering
color#fffMakes caption text white for contrastText readability
text-shadow0 1px 2px rgba(0,0,0,.6)Adds subtle shadow behind textImproves text visibility on images
text-aligncenterCenters text inside caption boxVisual balance
Concept Snapshot
Bootstrap carousel captions use a div with class 'carousel-caption' positioned absolutely over images. Captions are centered horizontally near the bottom with white text and shadow for readability. Responsive classes like 'd-none d-md-block' control caption visibility on different screen sizes. Only the active slide and its caption are visible at a time. Adding 'data-bs-ride="carousel"' enables automatic slide transitions with caption updates.

Practice

(1/5)
1. What is the purpose of the carousel-caption class in a Bootstrap carousel?
easy
A. To add text overlays on each slide explaining the content
B. To control the slide transition speed
C. To add navigation arrows to the carousel
D. To set the background color of the carousel

Solution

  1. Step 1: Understand the role of carousel-caption

    The carousel-caption class is used inside each carousel-item to add text overlays on slides.
  2. Step 2: Differentiate from other carousel features

    Other options control speed, navigation, or styling but do not add text overlays.
  3. Final Answer:

    To add text overlays on each slide explaining the content -> Option A
  4. Quick Check:

    carousel-caption adds text overlays = C [OK]
Hint: Remember captions explain slides visually [OK]
Common Mistakes:
  • Confusing caption with navigation controls
  • Thinking it changes slide speed
  • Assuming it styles background color
2. Which of the following is the correct way to add a caption inside a Bootstrap carousel slide?
easy
A. <caption>Caption Text</caption> inside carousel-item
B. <div class='carousel-caption'>Caption Text</div> inside carousel-item
C. <div class='carousel-text'>Caption Text</div> outside carousel-item
D. <span class='carousel-caption'>Caption Text</span> inside carousel-inner

Solution

  1. Step 1: Identify correct caption container

    The Bootstrap documentation specifies using <div class='carousel-caption'> inside each carousel-item.
  2. Step 2: Check other options for correctness

    <caption> is for tables, carousel-text is not a Bootstrap class, and span is less common and outside the item is incorrect.
  3. Final Answer:

    <div class='carousel-caption'>Caption Text</div> inside carousel-item -> Option B
  4. Quick Check:

    Use div.carousel-caption inside carousel-item = B [OK]
Hint: Use div with class carousel-caption inside each slide [OK]
Common Mistakes:
  • Using <caption> tag which is for tables
  • Placing caption outside carousel-item
  • Using wrong class names like carousel-text
3. Given this snippet inside a Bootstrap carousel slide:
<div class='carousel-caption text-start'>Caption</div>

What will be the alignment of the caption text when rendered?
medium
A. Text hidden and not visible
B. Text centered horizontally
C. Text aligned to the right side of the slide
D. Text aligned to the left side of the slide

Solution

  1. Step 1: Understand Bootstrap text alignment classes

    The class text-start aligns text to the left side in Bootstrap.
  2. Step 2: Apply alignment to carousel-caption

    Since carousel-caption contains text-start, the caption text will appear left aligned on the slide.
  3. Final Answer:

    Text aligned to the left side of the slide -> Option D
  4. Quick Check:

    text-start means left aligned = A [OK]
Hint: text-start means left alignment in Bootstrap [OK]
Common Mistakes:
  • Confusing text-start with center or right alignment
  • Assuming captions are always centered
  • Thinking text-start hides text
4. You wrote this code inside a Bootstrap carousel slide:
<div class='carousel-caption text-center'>Welcome</div>

But the caption text does not appear on the slide. What is the likely cause?
medium
A. Missing carousel-item wrapper around the caption
B. Using text-center hides the caption
C. The caption must be outside carousel-inner
D. Bootstrap requires captions to be <span> not <div>

Solution

  1. Step 1: Check caption placement rules

    Bootstrap requires carousel-caption to be inside a carousel-item for it to show properly.
  2. Step 2: Evaluate other options

    text-center does not hide text, captions must be inside carousel-inner, and div is the correct tag.
  3. Final Answer:

    Missing carousel-item wrapper around the caption -> Option A
  4. Quick Check:

    Caption must be inside carousel-item = A [OK]
Hint: Always nest captions inside carousel-item div [OK]
Common Mistakes:
  • Placing caption outside carousel-item
  • Thinking text-center hides text
  • Using wrong tag for caption
5. You want to create a Bootstrap carousel with three slides, each having a caption aligned differently: first left, second center, third right. Which code snippet correctly applies these caption alignments?
hard
A.
<div class='carousel-item active'>
  <div class='carousel-caption text-center'>First</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-center'>Second</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-center'>Third</div>
</div>
B.
<div class='carousel-item active'>
  <div class='carousel-caption text-end'>First</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-start'>Second</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-center'>Third</div>
</div>
C.
<div class='carousel-item active'>
  <div class='carousel-caption text-start'>First</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-center'>Second</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-end'>Third</div>
</div>
D.
<div class='carousel-item active'>
  <div class='carousel-caption text-center'>First</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-end'>Second</div>
</div>
<div class='carousel-item'>
  <div class='carousel-caption text-start'>Third</div>
</div>

Solution

  1. Step 1: Match caption alignment classes to slides

    The first slide uses text-start for left alignment, second uses text-center for center, and third uses text-end for right alignment.
  2. Step 2: Verify code structure and correctness

    Each caption is inside its carousel-item with correct alignment classes matching the requirement.
  3. Final Answer:

    Code snippet with first left, second center, third right using text-start, text-center, text-end respectively -> Option C
  4. Quick Check:

    Use text-start, text-center, text-end for left, center, right captions = D [OK]
Hint: Use text-start, text-center, text-end for left, center, right [OK]
Common Mistakes:
  • Mixing alignment classes order
  • Using same alignment for all captions
  • Placing captions outside carousel-item
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard