How To Align Text And Image In the Same Line In CSS

In this tutorial, you will learn how to align text and images on the same line in CSS. You can achieve this using several methods in CSS, and we’ll discuss two of the most common, namely flex container and inline-block display.

Using Flex Container

Step 1: Create the HTML Structure

First, you need to create the HTML structure containing the text and image elements you want to align in the same line.

The <div> element with the class “flex-container” will be the container for both the <img> and the <p> elements.

Step 2: Add CSS for Flex Container

To align the <img> and <p> elements, apply the display: flex property to the “flex-container” class.

Using Inline-Block Display

Step 1: Create the HTML Structure

Similar to the previous method, first create the HTML structure containing the text and image elements.

Notice that we added the class “align-inline” to both the <img> and <p> elements for styling purposes.

Step 2: Add CSS for Inline-Block Display

To align the <img> and <p> elements, apply the display: inline-block property to the “align-inline” class.

Full Code

Here’s the full code including both the HTML and CSS for the two methods explained above:

Conclusion

In this tutorial, you learned how to align text and images on the same line in CSS using both the flex container and inline-block display methods. Now you can implement these techniques to create a visually appealing layout for your website.