How can i set a <textarea>
to consume 100% width and height of the browser window?
For example, the following does not work:
html, body, textarea {
margin: 0;
padding: 0;
border: 0;
width: 100%;
height: 100%;
}
<textarea>Text goes here</textarea>
jsFiddle
Because it consumes slightly over 100% of the window, causing a scrollbar to appear:
How do i make a <textarea>
consume 100% of the space?
The issue is the common white space issue of inline-block
/inline
element due to vertical alignment. If you check dev tools of google you will see this:
So to fix it you simply need to adjust vertical alignment or make the textarea a block element (like provided in the other answers):
html, body, textarea {
margin: 0;
padding: 0;
border: 0;
width: 100%;
height: 100%;
}
textarea {
vertical-align:top;
}
<textarea>Text goes here</textarea>
This will work. or just add display:block
to textarea in your fiddle.
html, body {
margin: 0;
padding: 0;
border: 0;
}
* {
box-sizing: border-box;
}
textarea {
width: 100%;
height: 100vh;
display: block;
}
<textarea placeholder="message"></textarea>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With