Skip to content
Tech News
← Back to articles

Better Icon and Label Alignment

read original more articles
Why This Matters

This is a practical CSS/UI design tip addressing a subtle but common frontend problem: aligning icons with multi-line text labels in lists. While niche, it matters because such small details significantly affect perceived polish and usability in real-world interfaces, and developers often struggle with flexbox's default centering behavior in these cases.

Key Takeaways

There is a common design pattern that sometimes gets missed or overlooked. It’s having a list of items, each with an icon. When the text is one line, the icon is centered, but when the text has multiple lines, the icon is still centered but looks odd.

Here is an example:

Throughout this article, I will show two solutions that I use based on the HTML:

The icon is an HTML element (e.g., <svg> or <img> )

or ) The icon is added via a pseudo-element as a background image

The icon in the markup

In this case, we have a container with the icon and the content. Usually, we use flexbox. Like so:

< ul class = " list " > < li class = " list-item " > < svg class = " icon " > </ svg > < span class = " label " > How to align an icon to a label. </ span > </ li > </ ul >

.list-item { display : flex ; align-items : center ; gap : 0.5rem ; }

By default, it looks okay. Here it is:

... continue reading