InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search
  • Home
  • > Tutorials
  • > CSS cookbook

CSS – how to align image and text in center vertically

By admin | Last updated on Sep 4, 2016

We frequently need to center text and images when we are writing HTML/CSS. This can be done by using vertical-align:middle property on the child element which needs to be centrally aligned.

css-text-image-vertically-middle-aligned

Example

<style type="text/css">
.container {border: 1px solid lightgray;}
.center {vertical-align:middle;display:inline-block;}
</style>
<div class=container>
Hello
<img class="center" src="/img/elephant1.jpg">
<div class="center">Hello2</div>
</div>
refresh done
try it online

Few points to note about vertical-align

  1. The elements to be aligned should be either display:inline or display:inline-block
  2. We need to apply vertical-align:middle to elements inside a container. These elements then align in middle of their container.

Suggested posts:

  1. PHP how to get current url
  2. CSS transform – translateX and translateY
  3. jQuery – text input field – change keyup and paste events
  4. CSS float – floating left, right and clearing
  5. Javascript – implement class using function
  6. Vim – show line numbers
  7. Javascript – catch errors using window.onerror
  8. CSS justify-content – flexbox children aligment
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS cookbook, CSS layout, HTML, Tutorials, Web Development
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress