Space between link and icon, fontawesome

HtmlCssFont Awesome

Html Problem Overview


What's the best way to get a space between the link/paragraph and the icon?

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply"></i>Change</a>

Doesn't work to just put a space before the text because it will be changed back when you minify/uglify the project.

I tried with all kinds of padding and margins. Can't get them to separate.

Html Solutions


Solution 1 - Html

I would use the .fa-fw class. For example: <i class="fa fa-cog fa-fw"> This adds a visual space (that won't get stripped out) and it's consistent, so when/if the elements stack it looks a lot better.

Instructions: https://fontawesome.com/how-to-use/on-the-web/styling/fixed-width-icons enter image description here

Solution 2 - Html

Don't know if is the best but you can add some margin-right to the i element:

i {
  margin-right: 10px;
}

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply"></i>Change</a>

Solution 3 - Html

Old question but I didn't liked any of these answers so I did it this way:

 <i class="fa fa-cloud"></i> <span class="ml-1">Resume</span> 

I kinda hate CSS or dirty html and I prefer working only with classes but fa-fw isn't useful with some icons. Not sure if span is the way to go but it looks good in my project.

So you can just wrap your text around something and give it a margin in which direction you want.

Solution 4 - Html

I guess i is display: inline so you'll have to set its display to inline-block for margin-right to work :

i {
  display: inline-block;
  margin-right: 1em;
}

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply"></i>Change</a>

Solution 5 - Html

There are 2 spaces you need to add to make the UI look good. First, before the icon and a little space in between the icon and the text field.

So for the first case you need to add a font awesome class

> fa-fw

class. for the second case, we just need a Non-Breaking Space.

>  

This way you will not need an extra class to be added.

Below is a sample code to explain this.

<div class="list-group">
  <a class="list-group-item" href="#"><i class="fa fa-home fa-fw" aria-hidden="true"></i>&nbsp; Home</a>
  <a class="list-group-item" href="#"><i class="fa fa-book fa-fw" aria-hidden="true"></i>&nbsp; Library</a>
  <a class="list-group-item" href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; Applications</a>
  <a class="list-group-item" href="#"><i class="fa fa-cog fa-fw" aria-hidden="true"></i>&nbsp; Settings</a>
</div>

Solution 6 - Html

Since I just came across the same question I took a closer look at Christina's suggestion from the font-awesome example page (sorry, I'm not allowed to just comment yet).

<div class="list-group">
<a class="list-group-item" href="#"><i class="fa fa-home fa-fw" aria-hidden="true"></i>&nbsp; Home</a>
<a class="list-group-item" href="#"><i class="fa fa-book fa-fw" aria-hidden="true"></i>&nbsp; Library</a>
<a class="list-group-item" href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; Applications</a>
<a class="list-group-item" href="#"><i class="fa fa-cog fa-fw" aria-hidden="true"></i>&nbsp; Settings</a>
</div>

The most distance here is gained by &nbsp; (see screen 1) rather than from fa-fw see screen 2 since this is just unifying the width of the font-icon itself, so for a nicer look you may want to go for both.

&nbsp; (which will be interpreted as a space then) also should not make any troubles while minifying based on some quick tests.

Solution 7 - Html

Just use this:

a > i{
  padding-right:10px;
}

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply  "></i>Change</a>

Solution 8 - Html

<i class="fa fa-cloud mr-2"></i> 

This integrates Bootstrap as well as does not require for any extra tags!

Solution 9 - Html

None of the answers here worked for me. I had to do this:

<i class="fa fa-reply"><span>Change</span></i>

i span {
  display: inline-block;
  margin-left: 0.3rem;
}

Solution 10 - Html

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply" style="padding-right:5px"></i>Change</a>

you can do inner css after -class="fa fa-reply"- put -style="padding-right:5px"-

note: if you doing more then one icon type the padding size will be different by 1 or -1 px

or just put a space before the word like this

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-
awesome.min.css" rel="stylesheet">
<a href="#/upgrade/selection"><i class="fa fa-reply"></i> Change</a>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoeView Question on Stackoverflow
Solution 1 - HtmlChristinaView Answer on Stackoverflow
Solution 2 - Htmluser2019037View Answer on Stackoverflow
Solution 3 - HtmlEduardView Answer on Stackoverflow
Solution 4 - HtmlsodawillowView Answer on Stackoverflow
Solution 5 - HtmlHarshit PantView Answer on Stackoverflow
Solution 6 - HtmlChristoph FarnleitnerView Answer on Stackoverflow
Solution 7 - HtmlRafiqul IslamView Answer on Stackoverflow
Solution 8 - HtmlJason SaldañaView Answer on Stackoverflow
Solution 9 - HtmlVijayanand SettinView Answer on Stackoverflow
Solution 10 - HtmlahmedView Answer on Stackoverflow