Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A How to make the text box such that its placeholder goes up and arranges itself in the centre of the border upon clicking?

How to make the placeholder so that it goes to the top of the border line on click? For example, when you go to Gmail and click on the input field, the placeholder text goes up and arranges itself...

1 answer  ·  posted 3y ago by nobodyImportant‭  ·  edited 3y ago by hkotsubo‭

Question javascript html css
#4: Post edited by user avatar hkotsubo‭ · 2021-09-10T19:00:12Z (over 3 years ago)
Removed noise, added correct syntax highlight
How to make the text box such that its placeholder goes up and arranges itself in the centre of the border upon clicking?
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • Can anyone show me how I could do that? I would like to do it with CSS and HTML only, but JavaScript would also suffice. Thanks.
  • (P.S. Please do let me know if my question is off-topic.)
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it doesn't work:
  • ```html
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • ```
  • Can anyone show me how I could do that? I would like to do it with CSS and HTML only, but JavaScript would also suffice.
#3: Post edited by user avatar nobodyImportant‭ · 2021-09-09T19:03:11Z (over 3 years ago)
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • Can anyone show me how I could do that? Thanks.
  • (P.S. Please do let me know if my question is off-topic.)
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • Can anyone show me how I could do that? I would like to do it with CSS and HTML only, but JavaScript would also suffice. Thanks.
  • (P.S. Please do let me know if my question is off-topic.)
#2: Post edited by user avatar nobodyImportant‭ · 2021-09-09T19:02:36Z (over 3 years ago)
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • Can anyone show me how I could do that? Thanks.
  • How to make the `placeholder` so that it goes to the top of the border line on click?
  • For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:
  • Before clicking:
  • > ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)
  • After clicking in the box:
  • > ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)
  • The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.
  • Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:
  • <!DOCTYPE html>
  • <html>
  • <head>
  • <style>
  • input[type=password] {
  • width: 100%;
  • padding: 12px 20px;
  • margin: 8px 0;
  • box-sizing: border-box;
  • border: 1px solid #cccc;
  • -webkit-transition: 0.5s;
  • transition: 0.5s;
  • outline: none;
  • }
  • input[type=password]:focus {
  • border: 2px solid blue;
  • }
  • </style>
  • </head>
  • <body>
  • <form>
  • <input type="password" id="pass" name="pass" placeholder="Enter your password">
  • </body>
  • </html>
  • Can anyone show me how I could do that? Thanks.
  • (P.S. Please do let me know if my question is off-topic.)
#1: Initial revision by user avatar nobodyImportant‭ · 2021-09-09T19:01:38Z (over 3 years ago)
How to make the text box such that its placeholder goes up and arranges itself in the centre of the border upon clicking?
How to make the `placeholder` so that it goes to the top of the border line on click?

For example, when you go to [Gmail](https://accounts.google.com/signin/v2/challenge/pwd?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYam8XutnHkPtz69Y1z6fBVjoUxg0EJaZdp70njDom4_RG15iJ_ypwwKmH_7) and click on the `input` field, the placeholder text goes up and arranges itself to the left and in centre of the border-line. Here are screenshots of what I mean:

Before clicking:
> ![Before clicking the text box](https://software.codidact.com/uploads/6fip8EdwVb8CzoEwnuXjN7Ct)

After clicking in the box:
> ![After the text box is being clicked](https://software.codidact.com/uploads/RE5SQFZ7gqVJh88K4AfxHyqz)



The placeholder text ('Enter your password' in this case) goes up smoothly as you click in the box.

Unfortunately, I'm not fluent in programming enough to do that myself. The best I could do was this, but it's still a failure:



    <!DOCTYPE html>
    <html>
    <head>
    <style> 
    input[type=password] {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
    border: 1px solid #cccc;
    -webkit-transition: 0.5s;
    transition: 0.5s;
    outline: none;
    }

    input[type=password]:focus {
    border: 2px solid blue;
    }
    </style>
    </head>
    <body>


    <form>
    <input type="password" id="pass" name="pass" placeholder="Enter your password">
    
    </body>
    </html>


Can anyone show me how I could do that? Thanks.