Display icon next to input field

icon in input field bootstrap
how to add icon in textbox in html
clear icon inside input text bootstrap
image inside input box
input with icon
&cross icon in input field
input show icon
image over input field

I am trying to make it so that the label is directly on top of an input field, and I want an icon to display right next to said input field.

@import url("//fonts.googleapis.com/icon?family=Material+Icons");

input,
label {
    display: block;
}
<div>
    <label for="username">Username</label>
    <input id="username" placeholder="Username" class="">
    <i class="material-icons">accessibility</i>
</div>

@import url("//fonts.googleapis.com/icon?family=Material+Icons");

label {
  display: block;
}

input{
  display:inline;
  }
<div>
  <label for="username">Username</label>
  <input id="username"
         placeholder="Username"
         class="">
  <i class="material-icons">accessibility</i>
</div>

How To Create a Form with Icons, with Icons. ❮ Previous Next ❯ How To Create an Icon Form <input class="​input-field" type="text" placeholder="Username" name="usrnm"> display: flex; Today’s post is a relatively simple tip to add an icon into an HTML text input using CSS so that it sits inside the input box and the text does not appear over it at all. Working Example. Here’s a working example. It may not work if you are using a feed reader; if not then click through to view this post in a web browser.

The input must be displayed as an inline-block

 label {
   display: block;
 }

 input {
    display: inline-block;
 }

https://jsfiddle.net/51zrg6ms/2/

CSS to put icon inside an input element in a form, To add icon inside the input element the <i> tag and <span> tag are used widely to add icons on the webpages. To add input class = "input-field" type = "text" >. Visually, the icon is "inside" the input field, and as such, I would expect the focus state to include the icon's area – mix3d Mar 13 '19 at 17:21 1 I see your point, however it doesn't bother me, or affect how I would use the input.

For those coming across this post in a search, there is a thread on the MaterializeCSS repo on various ways to implement this. See: https://github.com/Dogfalo/materialize/issues/1214

I'm using the solution posted by amikeret in this reply: https://github.com/Dogfalo/materialize/issues/1214#issuecomment-430598527

His code is

.input-field {
  // Add inset definition to .prefix
  .prefix {
    &:not(.inset) {
      & ~ input,
      & ~ textarea,
      & ~ label,
      & ~ .validate ~ label,
      & ~ .helper-text,
      & ~ .autocomplete-content {
        margin-left: 3rem;
      }
    }
    &.inset {
      & ~ input,
      & ~ textarea,
      & ~ label,
      & ~ .validate ~ label,
      & ~ .helper-text,
      & ~ .autocomplete-content {
        margin-left: 0;   // This is a patch until it's incorporated into the framework
        padding-left: 3rem;
      }
    }
  }

  // Suffix Icons
  .suffix {
    position: absolute;
    width: $input-height;
    font-size: $input-icon-size;
    transition: color .2s;
    top: ($input-height - $input-icon-size) / 2;
    right: 0;
    text-align: right;

    &.active { color: $input-focus-color; }
  }
  .suffix {
    & ~ input,
    & ~ textarea,
    & ~ label,
    & ~ .validate ~ label,
    & ~ .helper-text,
    & ~ .autocomplete-content {
      width: calc(100% - 3rem);
    }
    &:not(.inset) {
      & ~ input,
      & ~ textarea,
      & ~ label,
      & ~ .validate ~ label,
      & ~ .helper-text,
      & ~ .autocomplete-content {
        margin-right: 3rem;
      }
    }
    &.inset {
      & ~ input,
      & ~ textarea,
      & ~ label,
      & ~ .validate ~ label,
      & ~ .helper-text,
      & ~ .autocomplete-content {
        padding-right: 3rem;
      }
    }
  }
  .suffix ~ label { margin-right: 3rem; }
  &.col {
    .suffix ~ label,
    .suffix ~ .validate ~ label {
      width: calc(100% - 3rem - #{$gutter-width});
    }
  }

  // What if we have both prefix and suffix?
  .prefix ~ .suffix ~ input {
    width: calc(100% - 6em);
  }
  &.col {
    .suffix ~ .suffix ~ label,
    .suffix ~ .suffix ~ .validate ~ label {
      width: calc(100% - 6rem - #{$gutter-width});
    }
  }
}

// Inset icons
.material-icons {
  &.inset {
    font-size: $input-icon-size * .75;
    top: ($input-height - $input-icon-size) / 2 * 1.5;
  }
  &.actionable {
    cursor: pointer;
    z-index: 2;
  }
}

An icon next to the html5 date input field - HTML-CSS, My requirement is to display a date (calendar) icon next to the html5 date input field and clicking the icon will popup a date picker. Current  Meaning that if I put an input and an img next to each other, the img is a few pixels higher than the input, but that varies by browser. The closest i can get is by making it a button that is styled with css to use my custom image. It works in Chrome, ie7, and ie10.

Flexbox: Inputs with icons, Flexbox solves the age old problem of displaying inputs alongside icons, without odd CSS hacks. Was used as a demo in a Smashing Magazine article, Marc How To Create an Icon Form Step 1) Add HTML: Use a <form> element to process the input. You can learn more about this in our PHP tutorial. Then add inputs for each field:

Tips for Aligning Icons to Text, Icons. They're popular. They help complement content (most of the time). icons are always crisp and proportional, regardless of the text next to it. where aligning icons comes into play, such as buttons, form fields, Hm… with svg you can basically display them as inline blocks and then align properly. The <input> tag specifies an input field where the user can enter data. The <input> element is the most important form element. The <input> element can be displayed in several ways, depending on the type attribute. The different input types are as follows: <input type="button"> <input type="checkbox"> <input type="color"> <input type="date">

How to Add Font Awesome Icons to Your Input Fields, I tried in my code however the icon doesn't stays within the box and goes below. Please enable JavaScript to view the comments powered by Disqus. Related  To add icon inside the input element the <i> tag and <span> tag are used widely to add icons on the webpages. To add any icons on the webpages or in some specific area, it needs the fontawesome link inside the head tag. The fontawesome icon can be placed by using the fa prefix before the icon’s name.

Comments
  • Do You need it just after the input field ??
  • Yes, so the icon should be to the right of the input field (not below, as it is in the jsfiddle).
  • The simplest change is just to remove input from your CSS rule: input, label { display: block; } becomes label { display: block; }
  • You don't even need the input { display: inline; } since inline is the default for an <input>
  • No, it doesn't need to be inline-blockinline works fine and is the default display property for an input element.
  • Yes you can; but personally I Prefer inline-block if you like to add some margins and paddings later for more perfect positioning.