How to justify button icons and put them next to the text

Introduction

When designing a website, the user interface plays a crucial role in enhancing user experience. One of the common elements that contribute to a user-friendly interface is the use of buttons with icons. Icons can provide a visual cue that complements the text, making it easier for users to understand the button’s function. However, aligning these icons properly next to the text can sometimes be challenging, especially when you can’t modify the HTML structure. This article aims to guide our users on how to align icons next to text in buttons effectively using CSS.

The Challenge

In many cases, icons are positioned at the extreme left or right of a button, which can lead to a less intuitive user experience. The challenge is to align these icons next to the text within the button, without altering the HTML structure.

The CSS Solution

CSS offers various properties to control the layout and positioning of elements. Here’s a sample CSS code snippet that aligns the icon next to the text.  

To use the following code go to your bio page editor, then select the Settings tab, scroll down and use the Custom CSS box to add the code:

.btn-custom i {
  position: relative !important;
  left: auto !important;
  margin-left: auto !important;
  margin-right: 10px !important;
}

Advantages of Using CSS

  1. Simplicity: CSS is straightforward to implement and doesn’t require additional dependencies.
  2. Performance: Being a client-side solution, it doesn’t put any load on the server.
  3. Maintainability: Easier to manage as you only need to update the stylesheet.