Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
CSS width of input element's contents. min-content doesn't work for inputs

min-content and max-content don't seem to care about the input element's value:

input {
  border: 1px solid black;
  width: min-content;
}
<input type="text">

CSS totally ignores the input's value when figuring out min-content, just using some default width that never changes no matter the contents:

enter image description here

How can I make the CSS take the "content" (value) width into account:

enter image description here

Without using javascript to set width, min-width or max-width

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is not possible without JavaScript.

You have to programmatically set the input's width to the length of its value. This can be simplified with the ch unit.

document.querySelector('input').addEventListener('input', function() {
  this.style.width = this.value.length + 'ch'
})
<input type="text">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!