Align Inline SVG with Text Using CSS vertical-align

Aligning inline SVG icons with adjacent text is a common front-end challenge because browser defaults align inline elements to the baseline, causing icons to look unnaturally raised. This guide explains why this misalignment occurs and how to utilize the vertical-align property alongside relative units (em or ex) to achieve pixel-perfect, scalable alignment without breaking text flow or relying on flexbox hacks.

Why Default Alignment Fails

By default, SVG elements are treated as inline content. Browsers place inline elements on the baseline of the text. Because text has descenders (like the tail of a “g” or “y”) and capital letter heights that sit above the baseline, placing the bottom edge of an SVG directly on the baseline causes the icon to appear too high relative to the surrounding words.

The most robust technique is to size the SVG using em units and apply a negative relative offset using vertical-align. This ensures the icon scales automatically whenever the parent font size changes.

.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  fill: currentColor;
}

Choosing the Right vertical-align Value

Depending on the icon set and typeface design, the exact offset may vary slightly:

  1. Negative em Values (-0.125em to -0.2em):
    This is the industry-standard approach used by modern icon libraries. An offset between -0.125em (1/8th of the font size) and -0.15em shifts the icon down just enough to center its bounding box with the text’s cap height rather than the baseline.

  2. vertical-align: middle:
    This value aligns the vertical midpoint of the SVG with the baseline of the parent box plus half the x-height of the font. While it improves alignment instantly, it can sometimes leave the icon slightly off-center compared to uppercase letters.

  3. vertical-align: text-bottom:
    Aligns the bottom of the SVG with the bottom of the parent element’s font. This works well for square icons that need to sit flush with the lowest point of typical text characters.

Key Rules for Perfect Icon Alignment