How to Vertically Align Text in CSS
Having trouble aligning text vertically with CSS? All you need to do is use the vertical-align
property. Works for tables as well:
Copied to clipboard! Playground
<style>
.top { vertical-align: top; }
.middle { vertical-align: middle; }
.bottom { vertical-align: bottom; }
</style>
<table border="1">
<tbody>
<tr>
<td class="top">I'm at the top</td>
<td class="middle">I'm in the middle</td>
<td class="bottom">I'm at the bottom</td>
</tr>
</tbody>
</table>
The above example, wil produce the following:
I'm at the top | I'm in the middle | I'm at the bottom |
Apart from the three values, it can also take the value of:
baseline
: it's initial value, the element is aligned to the baseline of its parent.sub
: Aligns the elements to the subscript-baseline of its parent.super
: Aligns the elements to the superscript-baseline of its parent.text-top
: Aligns the top of the element with the top of its parent element's font.text-bottom
: Aligns the bottom of the element with the bottom of its parent element's font.
Resources:
π More Webtips
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies:
Courses
CSS - The Complete Guide (including Flexbox, Grid and Sass)
Including Flexbox, Grid, and Sass
Whether you're learning CSS for the first time or brushing up on your CSS skills and diving even deeper, this course is for you. Every web developer has to know CSS.
The HTML & CSS Bootcamp
From Zero to Expert!
This course covers flexbox, CSS grid, animations, responsive design, and much more! You will find tons of exercises & projects inside this course.
The Creative HTML5 & CSS3 Course
Build Awesome Websites
Learn HTML5 and CSS3 by creating three amazing, well-designed and animated websites from scratch.