Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Media Objects

Bootstrap Media Objects are used to display content where an image or icon is placed beside related text. They are useful for comments, messages, profiles, notifications and other list-based content.

Simple Explanation: A Media Object is a layout where an image or icon appears on one side and related text appears beside it. For example, a user profile picture can appear on the left and the user's name and message can appear on the right.

What is a Media Object?

A Media Object is a common web design pattern used to arrange an image, icon or other media beside descriptive content.

The media element is normally placed on one side, while the text content is displayed next to it.

Simple Explanation: Imagine a comment section. The user's profile picture is on the left, and the user's name, message and date are on the right. This is a typical Media Object layout.

1. Basic Media Object

A basic media object contains a media element and a content section placed beside it.

Simple Explanation: The image represents the media and the text beside it represents the related content.

Example

<div class="d-flex">

    <div class="flex-shrink-0">

        <img src="/Images/Boostrap/Image4.png"
             width="80"
             height="80"
             class="rounded-circle"
             alt="User">

    </div>

    <div class="flex-grow-1 ms-3">

        <h5>
            Rahul Sharma
        </h5>

        <p>
            Bootstrap is easy to learn.
        </p>

    </div>

</div>
Output:
User
Rahul Sharma

Bootstrap is easy to learn and very useful for responsive web development.

2. Media Object with Heading

A media object can contain a heading, paragraph, date and other related information.

Simple Explanation: We can use the right side of the media object to display as much related information as required.

Example

<div class="d-flex">

    <img src="/Images/Boostrap/Image4.png"
         width="70"
         height="70"
         class="rounded-circle"
         alt="Student">

    <div class="ms-3">

        <h5>
            Student Feedback
        </h5>

        <p>
            The Bootstrap course was very useful.
        </p>

        <small>
            Posted Today
        </small>

    </div>

</div>
Student
Student Feedback

The Bootstrap course was very useful.

Posted Today

3. Media Object Alignment

Bootstrap utility classes can be used to control the alignment of media content.

For example, align-self-center can be used to vertically center the media element.

Simple Explanation: Alignment utilities decide where the image should appear vertically compared with the text.

Example

<div class="d-flex">

    <img src="/Images/Boostrap/Image4.png"
         width="80"
         height="80"
         class="rounded-circle align-self-center"
         alt="Student">

    <div class="ms-3">

        <h5>
            Bootstrap Student
        </h5>

        <p>
            This image is vertically centered
            beside the content.
        </p>

    </div>

</div>
Student
Bootstrap Student

This image is vertically centered beside the content.

4. Nested Media Object

A media object can contain another media object inside its content area.

This is useful for comments and replies where one comment can contain another reply.

Simple Explanation: Nested means one media object is placed inside another media object's content.

Example

<div class="d-flex">

    <img src="/Images/Boostrap/Image4.png"
         width="70"
         height="70"
         class="rounded-circle"
         alt="User">

    <div class="ms-3">

        <h5>
            Rahul
        </h5>

        <p>
            Bootstrap is easy to understand.
        </p>

        <div class="d-flex">

            <img src="/Images/Boostrap/Image4.png"
                 width="55"
                 height="55"
                 class="rounded-circle"
                 alt="Reply">

            <div class="ms-3">

                <h6>
                    Amit
                </h6>

                <p>
                    Yes, I agree.
                </p>

            </div>

        </div>

    </div>

</div>
User
Rahul

Bootstrap is easy to understand.

Reply
Amit

Yes, I agree.

5. Media Object with Button

A media object can also contain buttons along with the heading and description.

Simple Explanation: We can place an action button such as View Profile, Read More or Reply inside the content area.

Example

<div class="d-flex">

    <img src="/Images/Boostrap/Image4.png"
         width="80"
         height="80"
         class="rounded-circle"
         alt="Trainer">

    <div class="ms-3">

        <h5>
            Bootstrap Trainer
        </h5>

        <p>
            Learn Bootstrap with practical examples.
        </p>

        <button class="btn btn-primary">
            View Profile
        </button>

    </div>

</div>
Trainer
Bootstrap Trainer

Learn Bootstrap with practical examples.

6. Media Object for Comments

Media Objects are commonly used to create comment sections on websites.

Simple Explanation: The profile image is displayed on the left, while the user's name, comment and date are displayed on the right.

Example

<div class="d-flex">

    <img src="/Images/Boostrap/Image4.png"
         width="65"
         height="65"
         class="rounded-circle"
         alt="User">

    <div class="ms-3">

        <h6>
            Priya
        </h6>

        <p>
            This Bootstrap topic is very easy to understand.
        </p>

        <small>
            10 minutes ago
        </small>

    </div>

</div>
User
Priya

This Bootstrap topic is very easy to understand.

10 minutes ago

7. Media Object for Notifications

Media Objects can also be used to create notification layouts.

Simple Explanation: An icon or image can be displayed on the left, while the notification message is displayed on the right.

Example

<div class="d-flex align-items-center">

    <img src="/Images/Boostrap/Image4.png"
         width="60"
         height="60"
         class="rounded-circle"
         alt="Notification">

    <div class="ms-3">

        <h6>
            New Course Available
        </h6>

        <p class="mb-0">
            Bootstrap Advanced course is now available.
        </p>

    </div>

</div>
Notification
New Course Available

Bootstrap Advanced course is now available.

8. Media Object for Profile

Media Objects are useful for displaying user or trainer profile information.

Simple Explanation: The profile picture appears on one side and profile information appears next to it.

Example

<div class="d-flex align-items-center">

    <img src="/Images/Boostrap/Image4.png"
         width="90"
         height="90"
         class="rounded-circle"
         alt="Trainer">

    <div class="ms-3">

        <h4>
            CIIT Trainer
        </h4>

        <p>
            Full Stack Development Trainer
        </p>

    </div>

</div>
Trainer

CIIT Trainer

Full Stack Development Trainer

Important Classes Used

Class Purpose
.d-flex Creates a flexible horizontal layout.
.flex-shrink-0 Prevents the media element from shrinking.
.flex-grow-1 Allows the content area to use available space.
.ms-3 Adds margin on the start side.
.align-self-center Vertically centers an individual element.
.align-items-center Vertically aligns flex items in the center.
.rounded-circle Makes a suitable image circular.
.img-fluid Makes an image responsive.

Common Mistakes

  • Forgetting to use a flex container such as d-flex.
  • Not adding spacing between the media and content.
  • Using very large fixed image dimensions.
  • Forgetting the alt attribute.
  • Not using responsive classes for mobile layouts.
  • Using unnecessary nested structures when a simple flex layout is enough.

Summary

  • Media Objects are used to place media beside related content.
  • d-flex creates the basic flexible layout.
  • ms-3 provides spacing between the image and content.
  • align-items-center aligns items vertically.
  • Media Objects are useful for comments, profiles, notifications and messages.
  • Media Objects can also be nested to create replies and discussion threads.
  • Responsive image and spacing utilities can be combined with Media Object layouts.