Tillitsdone
down Scroll to discover

Mastering CSS Vertical-Align for Web Development

Learn about the CSS vertical-align property, its use cases, and available options for aligning elements vertically.

Enhance your web design skills with this comprehensive guide.
thumbnail

Vertical Alignment in CSS

The vertical-align property in CSS controls the vertical positioning of elements within a line box. This includes aligning images with text and ensuring elements are properly positioned relative to each other. By using different vertical-align values, you can achieve various alignment effects, enhancing the overall appearance and readability of your web content.

Syntax

vertical-align: value;

Values

  • Keyword Values:
    • baseline
    • sub
    • super
    • text-top
    • text-bottom
    • middle
    • top
    • bottom
  • Length Values:
    • 10em
    • 4px
  • Percentage Values:
    • 20%
  • Global Values:
    • inherit
    • initial
    • revert
    • revert-layer
    • unset

Examples

To align an element to the baseline of its parent:

vertical-align: baseline;

To align an element to the top of its parent’s font:

vertical-align: text-top;

To raise an element by 10 pixels above the baseline:

vertical-align: 10px;

To position an element 20% above the baseline:

vertical-align: 20%;

Values for Inline Elements

Parent-Relative Values

  • baseline: Aligns the baseline of the element with the baseline of its parent.
  • sub: Aligns the baseline of the element with the subscript-baseline of its parent.
  • super: Aligns the baseline of the element with the superscript-baseline of its parent.
  • text-top: Aligns the top of the element with the top of the parent element’s font.
  • text-bottom: Aligns the bottom of the element with the bottom of the parent element’s font.
  • middle: Aligns the middle of the element with the baseline plus half the x-height of the parent.
  • <length>: Aligns the baseline of the element to the given length above the baseline of its parent.
  • <percentage>: Aligns the baseline of the element to the given percentage above the baseline of its parent, with the value being a percentage of the line-height property.

Line-Relative Values

  • top: Aligns the top of the element and its descendants with the top of the entire line.
  • bottom: Aligns the bottom of the element and its descendants with the bottom of the entire line.

Values for Table Cells

  • top: Aligns the content to the top of the table cell.
  • bottom: Aligns the content to the bottom of the table cell.
  • middle: Aligns the content to the middle of the table cell.
  • baseline: Aligns the content to the baseline of the table cell.
  • <length>: Aligns the content to the given length above the baseline of the table cell.
  • <percentage>: Aligns the content to the given percentage above the baseline of the table cell, with the value being a percentage of the line-height property.

Examples of vertical-align in Table Cells

To align the content to the top of a table cell:

td {
vertical-align: top;
}

To align the content to the middle of a table cell:

td {
vertical-align: middle;
}

To align the content to the bottom of a table cell:

td {
vertical-align: bottom;
}

Example Usage

To create a table where cells are aligned differently:

HTML:

<table>
<tr>
<td class="baseline">Baseline</td>
<td class="top">Top</td>
<td class="middle">Middle</td>
<td class="bottom">Bottom</td>
</tr>
</table>

CSS:

table {
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 10px;
}
.baseline {
vertical-align: baseline;
}
.top {
vertical-align: top;
}
.middle {
vertical-align: middle;
}
.bottom {
vertical-align: bottom;
}

Basic Example

HTML:

<div>
An <img src="frame_image.svg" alt="link" width="32" height="32" /> image with a default alignment.
</div>
<div>
An <img class="top" src="frame_image.svg" alt="link" width="32" height="32" /> image with a text-top alignment.
</div>
<div>
An <img class="bottom" src="frame_image.svg" alt="link" width="32" height="32" /> image with a text-bottom alignment.
</div>
<div>
An <img class="middle" src="frame_image.svg" alt="link" width="32" height="32" /> image with a middle alignment.
</div>

CSS:

img.top {
vertical-align: text-top;
}
img.bottom {
vertical-align: text-bottom;
}
img.middle {
vertical-align: middle;
}

Example: Vertical Alignment in a Line Box

HTML:

<p>
top: <img style="vertical-align: top" src="star.png" alt="star"/>
middle: <img style="vertical-align: middle" src="star.png" alt="star"/>
bottom: <img style="vertical-align: bottom" src="star.png" alt="star"/>
super: <img style="vertical-align: super" src="star.png" alt="star"/>
sub: <img style="vertical-align: sub" src="star.png" alt="star"/>
</p>
<p>
text-top: <img style="vertical-align: text-top" src="star.png" alt="star"/>
text-bottom: <img style="vertical-align: text-bottom" src="star.png" alt="star"/>
0.2em: <img style="vertical-align: 0.2em" src="star.png" alt="star"/>
-1em: <img style="vertical-align: -1em" src="star.png" alt="star"/>
20%: <img style="vertical-align: 20%" src="star.png" alt="star"/>
-100%: <img style="vertical-align: -100%" src="star.png" alt="star"/>
</p>

CSS:

img {
margin-right: 0.5em;
}
p {
height: 3em;
padding: 0 0.5em;
font-family: monospace;
text-decoration: underline overline;
margin-left: auto;
margin-right: auto;
width: 80%;
}

Example: Vertical Alignment in a Table Cell

HTML:

<table>
<tr class="bottom">
<td class="baseline">baseline</td>
<td class="top">top</td>
<td class="middle">middle</td>
<td>bottom</td>
<td>Row's style</td>
<td>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pretium felis eu sem mattis vulputate.
</td>
</tr>
</table>

CSS:

.baseline {
vertical-align: baseline;
}
.top {
vertical-align: top;
}
.middle {
vertical-align: middle;
}
.bottom {
vertical-align: bottom;
}

Browser Compatibility

The vertical-align property is widely supported across all major web browsers, ensuring that you can reliably use it to control the vertical alignment of elements in your web designs.

Browser Compatibility Table

BrowserVersionRelease Date
Chrome1.0December 2008
Edge12.0July 2015
Firefox1.0November 2004
Internet Explorer4.0September 1997
Safari1.0June 2003
Opera4.0June 2000

Practical Tips

  • Testing: Always test your web designs across multiple browsers to ensure consistent appearance and functionality.
  • Polyfills and Fallbacks: For older browsers that may have limited support for certain CSS properties, consider using polyfills or fallbacks to maintain compatibility.
  • Documentation: Refer to the official CSS specifications and browser documentation for the most up-to-date information on compatibility and any known issues.

See Also

For further exploration and understanding of related CSS properties and concepts, you may find the following resources helpful:

  • [Typical Use Cases of Flexbox]WebsiteUrl: Learn about the various applications of Flexbox, including how to center items within a container.
  • [line-height]WebsiteUrl: Understand how the line-height property affects the vertical spacing of text and how it interacts with vertical-align.
  • [text-align]WebsiteUrl: Explore the text-align property for horizontal text alignment, which complements vertical-align for comprehensive text layout control.
  • [margin]WebsiteUrl: Learn about the margin property and how it can be used to create space around elements, enhancing layout and readability.
  • [Understanding vertical-align]WebsiteUrl: Delve into an in-depth explanation of the vertical-align property, including its nuances and practical examples.
  • [Vertical-Align: All You Need To Know]WebsiteUrl: A comprehensive guide on the vertical-align property, covering its various uses and best practices.
  • [HTML Reference Guide]WebsiteUrl: Access a comprehensive reference for HTML elements, which can help you understand how to structure your web content effectively.
icons/logo-tid.svg Latest Blogs
Discover our top articles, selected to support the growth of your business.
https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R39_Sep_1440x697.jpg@webp Web Development Frameworks: React vs Vue vs Angular vs Svelte ตัวไหนน่าใช้ เปรียบเทียบ React vs Vue vs Angular vs Svelte แบบเข้าใจง่าย เจาะคุณสมบัติ และสรุปให้ว่าเหมาะกับใคร เพื่อให้ช่วยเลือก Framework ที่ใช่ในปี 2025 https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R38_Sep_1440x697.jpg@webp TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R36_Sep_1440x697.jpg@webp Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R35_Sep_1440x697.jpg@webp มือใหม่อยากเริ่มเขียนแอป ต้องใช้โปรแกรมและภาษาอะไรบ้าง? อยากเป็นนักพัฒนาแอปแต่ไม่รู้จะเริ่มยังไง พบกับแนวทางการเลือกเครื่องมือและภาษาเบื้องต้นพร้อมคำแนะ เพื่อก้าวสู่เส้นทางการเขียนแอปอย่างมั่นใจในบทความนี้ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R27_Sep_1440x697.jpg@webp เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R26_Sep_1440x697.jpg@webp Next js image การ Optimization รูปภาพแบบ Native ที่มีประสิทธิภาพสูง เรียนรู้วิธีใช้ Next.js Image เพื่อ Optimization การแสดงภาพบนเว็บไซต์ ด้วยเทคนิคบีบอัด ปรับขนาด Lazy Load และรองรับ Responsive ช่วยให้เว็บคุณโหลดเร็วขึ้นแน่นอน!
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
down Explore our best articles, cover a wide variety of technologies
Our knowledge base
196 Articles
Explore right
icons/logo-react.svg ReactJs
Popular JavaScript library for building user interfaces with a component-based architecture.
160 Articles
Explore right
icons/flutter.svg Flutter
UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.
144 Articles
Explore right
icons/logo-nodejs.svg Nodejs
JavaScript runtime for building scalable, high-performance server-side applications.
58 Articles
Explore right
icons/next-js.svg Nextjs
React framework enabling server-side rendering and static site generation for optimized performance.
38 Articles
Explore right
icons/tailwind.svg TailwindCSS
Utility-first CSS framework for rapid UI development.
36 Articles
Explore right
icons/code-outline.svg Typescript
Superset of JavaScript adding static types for improved code quality and maintainability.
126 Articles
Explore right
icons/code-outline.svg Golang
Programming language known for its simplicity, concurrency model, and performance.
67 Articles
Explore right
icons/code-outline.svg AstroJs
Astro is an all-in-one web framework. It includes everything you need to create a website, built-in.
38 Articles
Explore right
icons/code-outline.svg Jest
Versatile testing framework for JavaScript applications supporting various test types.
14 Articles
Explore right
icons/code-outline.svg Website development th
10 Articles
Explore right
icons/code-outline.svg Mobile application th
5 Articles
Explore right
icons/code-outline.svg Reactjs th
3 Articles
Explore right
icons/code-outline.svg Flutter th
3 Articles
Explore right
icons/code-outline.svg Nextjs th
1 Articles
Explore right
icons/code-outline.svg Software house th
1 Articles
Explore right
icons/code-outline.svg Nodejs th
1 Articles
Explore right
icons/code-outline.svg Typescript th
337 Articles
Explore right
icons/css-4.svg CSS
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
FacebookInstagramLinkedIn
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.