Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS vertical-align Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 17 - Views
⏳ 4 mins
💬 1 Comment
CSS vertical-align Property

Photo Credit to CodeToFun

🙋 Introduction

The vertical-align property in CSS controls how inline elements are aligned vertically relative to their parent element or to the line box.

This property is particularly useful for aligning text and other inline elements within a line of text or within a block container.

💡 Syntax

The syntax for the vertical-align property is straightforward. It can be applied to inline or table-cell elements, and you can specify various alignment values.

Syntax
Copied
Copy To Clipboard
element {
  vertical-align: value;
}

🎛️ Default Value

The default value of vertical-align is baseline, which aligns the baseline of the element with the baseline of its parent.

🏠 Property Values

ValueDescription
baselineAligns the baseline of the element with the baseline of its parent.
topAligns the top of the element with the tallest element on the line.
middleAligns the middle of the element with the middle of the parent element's font.
bottomAligns the bottom of the element with the lowest element on the line.
subAligns the element as subscript relative to the baseline.
superAligns the element as superscript relative to the baseline.
text-topAligns the top of the element with the top of the parent element's font.
text-bottomAligns the bottom of the element with the bottom of the parent element's font.

📄 Example

In this example, we'll use the vertical-align property to align text and images vertically within a line of text.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS vertical-align Example</title>
  <style>
    .inline-img {
      vertical-align: middle;
    }
  </style>
</head>
<body>
  <h1>Vertical Align Text and Image</h1>
  <p>
    <img src="image.png" alt="Example Image" class="inline-img">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The vertical-align property is well-supported across all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. It behaves consistently across different platforms.

🎉 Conclusion

The vertical-align property is a versatile tool for aligning inline elements vertically within their container.

Whether you're aligning text alongside images, adjusting the positioning of subscripts or superscripts, or fine-tuning the vertical alignment of table cells, understanding and using vertical-align can significantly enhance the layout and presentation of your web content.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy