Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative letter-spacing cut off text in input when right aligned

I'm trying to display numbers inside an <input> field using a negative letter-spacing value and text-align: right. However, the last character gets clipped (not fully rendered), even when zooming the browser in or out.

Digits 0950610 inside an input rectangle aligned right and having very tight tracking. Last digit, zero, is partially cut-off.

input {
    font-family: "MS-Mincho";
    font-size: 11pt;
    letter-spacing: -1pt;
    text-align: right;
}
<input type="text" value="09530610" />

I want to keep both the current letter-spacing and text-align values, but still prevent the last character from being visually cut off.

Is there a reliable CSS-only solution to avoid this clipping issue without changing the font or letter-spacing value? Any suggestions would be greatly appreciated!

P/S: Things I've already tried (but didn't work): padding-right, text-indent,...

like image 422
Giang Hoang Avatar asked Oct 23 '25 18:10

Giang Hoang


1 Answers

You can fix this issue by setting text-indent: 1px; on your input, and then change the direction of the element's text using the dir global attribute. dir does the same thing as direction but MDN recommends using dir whenever possible.

input {
  font-family: "MS-Mincho";
  font-size: 11pt;
  letter-spacing: -1pt;
  text-align: right;
  text-indent: 1px;
}
<input type="text" value="09530610" dir="rtl"/>
like image 107
Atlas Avatar answered Oct 26 '25 10:10

Atlas



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!