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

  • SEARCH
  • Home
  • 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 8916919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:22:11+00:00 2026-06-15T05:22:11+00:00

I have a couple of <input> elements that I need to have HTML5-like placeholders

  • 0

I have a couple of <input> elements that I need to have HTML5-like placeholders for. The kind that disappear on focus and reappear on blur only if the input has no text. I’ve seen a few javascript-heavy implementations and I’ve been looking for a lightweight (preferably css-only) solution.

Here’s the HTML:

<div class="email-container">
    <span class="default-value">Email</span>
    <input class="text-input" name="login" type="email"/>
</div>
<div class="pw-container">
    <span class="default-value">Password</span>
    <input class="text-input" name="login" type="pw"/>
</div>
  • 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-15T05:22:12+00:00Added an answer on June 15, 2026 at 5:22 am

    I couldn’t find anything that fit my bill perfectly (as in ‘css-only’), but I did come up with a couple of good solutions using jQuery:

    1. I set the background of the input to transparent and the z-index of the ‘placeholder’ text to -1. This allows me to click ‘on’ the text and actually click the input. See this jsFiddle.

    2. I allow the ‘placeholder’ text to sit over the input but I use a click handler on the text to transfer the focus to the input. See this jsFiddle.

    In both instances, the workhorse of the implementation is this jQuery code:

    $('.text-input').each(function(){
        var input = $(this);
        //Initially hide the default value if the input is non-empty
        input.siblings('.default-value').toggle(!input.val());
        input.on("focus blur", function(){
            if(input.val().length === 0){
                input.siblings('.default-value').toggle();
            }
        }
    )});​
    

    The other important piece to the puzzle was figuring out how to use position: absolute and position: relative to make the ‘placeholder’ text sit nicely inside the input while still allowing the input to move freely.

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

Sidebar

Related Questions

Hi, I have a couple of input type file elements like this : <input
I have couple of dozen pieces of data that I need to save and
I have a couple of span elements and I need to get the contents
I have a couple of input boxes that get dynamically created, and then filled.
I have couple resource DLLs that I currently load when application starts using following
We have couple different web-apps that share the same db link. The hibernate layer
ok I have couple of .NET classes that I want to use in VBA.
I have couple of input fields with the class link. All of them should
I have a CSV file with records that need to be sorted and then
I have a form that I generate new input fields to with javascript and

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.