Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parent of <textarea> is taller than <textarea> when the document has <!DOCTYPE html> in Chrome

Try pasting this HTML into a file and opening it in Chrome:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <div>
      <textarea></textarea>
    </div>
  </body>
</html>

The parent is a bit bigger than the textarea:

size of textarea's parent

This is only the case on Chrome (not Firefox).

I noticed that if I removed the doctype, it behaves normally - the parent is the correct size. My first thought is that it's just different default useragent styles. Here's a diff between the the user agent styles with and without the doctype:

useragent styles with and without doctype

So I tried matching the padding and the box-sizing like so:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <div>
      <textarea style="box-sizing: border-box; padding: 2px 0px 0px 2px;"></textarea>
    </div>
  </body>
</html>

But the problem doesn't go away. Any idea what's causing this?

(Sorry for the over-sized images - I'm not aware of any markdown tricks to make them a more reasonable size.)

like image 370
joe Avatar asked Oct 27 '25 12:10

joe


1 Answers

Yes, it is a chromium bug.

The best workaround is to set it to block type box.

textarea {
  display: block;
}
like image 74
devfieldnotes Avatar answered Oct 30 '25 02:10

devfieldnotes



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!