Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position HTML input cursor at beginning of centered placeholder

How can I position the cursor to be at the beginning of the placeholder (not the beginning of the input field) instead of the middle, while still keeping my placeholder text centered?

<input type="text" name="input_query" id="input_query" autofocus style="text-align: center; width: 100%" placeholder="Describe what's happening in your photo" autocomplete="off"/>

1 Answers

Use ::placeholder to apply CSS to the placeholder only:

input {
  width: 100%
}
input::placeholder {
  text-align: center;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autocomplete="off"/>

If you want the cursor to appear at the beginning of the placeholder, you can do something similar, though it's pretty weird and isn't centered once the user starts typing:

input {
  width: 65%;
  padding-left: 35%;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autocomplete="off"/>
like image 80
CertainPerformance Avatar answered Dec 23 '25 22:12

CertainPerformance



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!