Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to Vertically Align an Image Inside a Div in CSS ?
Next article icon

How to Vertically Align Text Next to an Image using CSS ?

Last Updated : 23 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Adding images into our websites is a common practice, and there are situations where text must be vertically aligned alongside an image. For example, a user’s name should appear immediately next to their profile picture, vertically aligned for optimal readability . In this article, we will see how to align text next to an image using various methods.

Adding images into our websites is a common practice, and there are situations where text must be vertically aligned alongside an image. For example, a user’s name should appear immediately next to their profile picture, vertically aligned for optimal readability.

Approaches Vertically Align Text Next to an Image:

Two effective methods can be used to vertically align text next to an image are:

  1. Using flexbox
  2. Using vertical-align CSS property

1. Using flexbox:

In this approach, we will use flexbox. For this, we will use CSS display property combined with align-items property. We need to create a parent element that contain both image and text. After declaring the parent element as flexbox using display: flex; we can align the items to the center using align-items: center;.


Syntax: 

.class_name {      display: flex;     align-items:center; }


Example: This example uses flexbox to vertically align text next to an image using CSS.
 

html
<!DOCTYPE html> <html>   <head>     <title>         How to Vertically Align Text         Next to an Image using CSS ?     </title>          <style>         .aligned {             display: flex;             align-items: center;         }                   span {             padding: 10px;         }     </style> </head>   <body>     <div class="aligned">         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20200327230544/g4gicon.png"             width="50" alt="">                      <span>GeeksforGeeks</span>     </div> </body>  </html> 

Output: 
 


2. Using vertical-align CSS property:

In this approach, we don't need to wrap our element in a parent element and use vertical-align property to vertically align elements directly.


Syntax: 

.class_name { vertical-align: middle; } 


Example: This example uses vertical-align property to vertically align text next to an image using CSS.
 

html
<!DOCTYPE html> <html>   <head>     <title>         How to Vertically Align Text         Next to an Image using CSS ?     </title>          <style>         img {             vertical-align: middle;         }     </style> </head>   <body>     <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20200327230544/g4gicon.png"             width="50" alt="">                  <span>         GeeksforGeeks (using vertical-align)     </span> </body>   </html> 

Output: 

 

CSS is the foundation of webpages, is used for webpage development by styling websites and web apps.You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.


Next Article
How to Vertically Align an Image Inside a Div in CSS ?
author
gurrrung
Improve
Article Tags :
  • Web Technologies
  • CSS
  • CSS-Misc

Similar Reads

  • How to vertically align text inside a flexbox using CSS?
    Vertically aligning text inside a flexbox involves positioning the text centrally within the vertical space of a flex container. This can be achieved using CSS properties such as align-items and justify-content to control the vertical alignment and centering of the text. Here we have some common app
    2 min read
  • How to Vertically Align an Image Inside a Div in CSS ?
    In this article, we are going to see how we can vertically align an image inside a div. Centering content both vertically and horizontally is one of the most important functions which needs to be done. Below are the approaches to vertically align an image inside a div in CSS:   Table of Content Usin
    4 min read
  • How to make a vertical wavy text line using HTML and CSS ?
    In this article, a wavy animated text is implemented using HTML and CSS. It is one of the simplest CSS effects. For a beginner, it is one of the best examples to learn the concept of CSS pseudo-elements. Approach: The basic idea of getting wavy texts is performed by using the combination of some CSS
    2 min read
  • How to Center an Image using text-align Property in CSS ?
    Aligning an image horizontally within a container can sometimes be challenging. In this article, we will explore how to center an image using the text-align property in CSS. Understanding the text-align PropertyThe text-align property in CSS is used to specify the horizontal alignment of text within
    2 min read
  • How to add lines besides a vertical text using SASS ?
    In this article, we will see how to add lines besides some vertical text using SASS. Approach: The HTML code is used to depict the basic structure of the body. Here, we define a division element with a class of wrapper to contain subsequent division elements. Another division element with a class of
    6 min read
  • How to wrap the text around an image using HTML and CSS?
    Here are three methods to make text around an image using HTML and CSS: 1. Using Float PropertyThe float property is the traditional way to position an image and allow text to wrap around it. [GFGTABS] HTML <html> <head> <style> .image-left { float: left; margin-right: 15px; } <
    2 min read
  • How to align an image and text vertically on the same line in React Bootstrap?
    ReactJS has a very beautiful way to align images and text vertically in the same line in React Bootstrap. ReactJS is a front-end library developed by Facebook to build various components of the front-end. Bootstrap is a CSS framework developed by Twitter for building CSS enriched front end websites.
    2 min read
  • How to Align Images Side By Side using CSS ?
    Images side by side means placing multiple images in a single row next to each other. This arrangement shows images in a horizontal line, making it great for photo galleries, and comparing pictures. To align images side by side using CSS, we can use flexbox or grid for layout. Table of Content Using
    2 min read
  • How to Vertically Align Text Within a Div in CSS?
    Aligning text vertically within a div can enhance the visual appeal of your web design. There are various approaches to achieving vertical alignment using CSS. 1. Using line-height PropertyThe line-height property is the easiest and most commonly used approach to align text within a div vertically.
    2 min read
  • How to Place Text Over an Image using CSS?
    Place Text Over an Image means overlaying text on top of an image using HTML and CSS. This effect is commonly achieved by placing the image and text inside a container and then using CSS techniques like absolute positioning, z-index, or flexbox to position the text over the image. Below are the appr
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences