Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:38:32+00:00 2026-06-15T13:38:32+00:00

I’d like to add an image icon to an input placeholder, like in this

  • 0

I’d like to add an image icon to an input placeholder, like in this picture:
enter image description here

Please note that this is a placeholder, so when the user starts typing, the icon also disappears.

I came with the following solution for webkit (Safari+Chrome) using ::-webkit-input-placeholder and ::before. Unfortunately, the straightforward application to mozilla seems not to work.

So my question is: is there a cross-browser solution to add an image icon to an input placeholder?

Solution for webkit:

#myinput::-webkit-input-placeholder::before { 
    content: ' ';
    position: absolute;
    top: 2px; /* adjust icon position */
    left: 0px;
    width: 14px; /* size of a single icon */
    height: 14px;
    background-image: url("/path/to/icons.png"); /* all icons in a single file */
    background-repeat: no-repeat;
    background-position: -48px 0px; /* position of the right icon */
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:38:33+00:00Added an answer on June 15, 2026 at 1:38 pm
    1. You can set it as background-image and use text-indent or a padding to shift the text to the right.
    2. You can break it up into two elements.

    Honestly, I would avoid usage of HTML5/CSS3 without a good fallback. There are just too many people using old browsers that don’t support all the new fancy stuff. It will take a while before we can drop the fallback, unfortunately 🙁

    The first method I mentioned is the safest and easiest. Both ways requires Javascript to hide the icon.

    CSS:

    input#search {
        background-image: url(bg.jpg);
        background-repeat: no-repeat;
        text-indent: 20px;
    }
    

    HTML:

    <input type="text" id="search" name="search" onchange="hideIcon(this);" value="search" />
    

    Javascript:

    function hideIcon(self) {
        self.style.backgroundImage = 'none';
    }
    

    September 25h, 2013

    I can’t believe I said "Both ways requires JavaScript to hide the icon.", because this is not entirely true.

    The most common timing to hide placeholder text is on change, as suggested in this answer. For icons however it’s okay to hide them on focus which can be done in CSS with the active pseudo-class.

    #search:active { background-image: none; }
    

    Heck, using CSS3 you can make it fade away!

    http://jsfiddle.net/2tTxE/


    November 5th, 2013

    Of course, there’s the CSS3 ::before pseudo-elements too. Beware of browser support though!

                Chrome  Firefox     IE      Opera   Safari
    :before     (yes)   1.0         8.0     4       4.0
    ::before    (yes)   1.5         9.0     7       4.0
    

    https://developer.mozilla.org/en-US/docs/Web/CSS/::before

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I need to clean up various Word 'smart' characters in user input, including but
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.