Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add font awesome icons to a form label

Is it possible to use font awesome icons within a label when creating a form for example.

if my form looks like this

<%= f.label :email %>
<%= f.email_field :email, :autofocus => true %>

How would i add the i class to the label?

I have tried this

<%= f.label :email, :class => 'icon-user' %>
<%= f.email_field :email, :autofocus => true %>

but this doesn't work?

like image 883
Richlewis Avatar asked Oct 23 '25 19:10

Richlewis


1 Answers

Try something like this (assuming email is a field of class User):

<%= f.label :email do %>
  <i class="icon-user"></i>
  <%= User.human_attribute_name :email %>
<%- end -%>
like image 88
DMKE Avatar answered Oct 26 '25 08:10

DMKE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!