Should I size a textarea with CSS width / height or HTML cols / rows attributes?
I recommend to use both. Rows and cols are required and useful if the client does not support CSS. But as a designer I overwrite them to get exactly the size I wish.
The recommended way to do it is via an external stylesheet e.g.
textarea { width: 300px; height: 150px;}
<textarea> </textarea>
use cols/rows or style-width/height to specify dimensions of textarea?
Please see this question: Should I size a textarea with CSS width / height or HTML cols / rows attributes?
I agree with the top answer. You use rows/cols in case CSS is not supported; if width or height are specified using CSS, they override the value derived from rows/cols.
sizing a textarea with CSS vs with cols and rows
cols
and rows
are relative to font size. height
and width
aren't.
http://jsfiddle.net/rVUEE/1/
EDIT: Saying they are relative to "font size" is a bit too simplistic. They take into account things such as line-height
and letter-spacing
if explicitly set as well.
How to setup textarea rows and resize using html plus css?
If you want to use multiples lines to show the text then use textarea element instead of input.
<textarea id="content " name="content " rows="5" placeholder="Write your content here " required > </textarea>
You can further define your css accordingly
textarea {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: white;
width: 100%;
padding: 12px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #a0a0a0;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
font-weight: normal;
height: 4em;
word-wrap: normal;
vertical-align: top;
overflow: auto;
}
textarea's rows, and cols attribute in CSS
width
and height
are used when going the css route.
<!DOCTYPE html>
<html>
<head>
<title>Setting Width and Height on Textareas</title>
<style>
.comments { width: 300px; height: 75px }
</style>
</head>
<body>
<textarea class="comments"></textarea>
</body>
</html>
why is textarea larger in width and height than iframe?
Different padding and border.
Set them the same and they have the same size
iframe, textarea {
width: 200px;
height: 200px;
border: 2px solid black;
padding: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- here's textarea: -->
<textarea name="texta" id="texta"></textarea>
<!-- here's iframe: -->
<iframe src="" ></iframe>
</body>
</html>
Related Topics
Align Image in Center and Middle Within Div
How to Prevent Input Type="Number" Getting Negative Values
Ng-App Vs. Data-Ng-App, What Is the Difference
Difference Between ≪Input Type='Submit' /≫ and ≪Button Type='Submit'≫Text≪/Button≫
Html Table With Horizontal Scrolling (First Column Fixed)
Select Dropdown With Fixed Width Cutting Off Content in Ie
How to Update Non-Jsf Components (Plain Html) With Jsf Ajax
How to Get the HTML Source of a Page from a HTML Link in Android
Full Width Backgrounds on Outlook '07/'10/'13
Best Approach to Real Time Http Streaming to Html5 Video Client
Flexbox Not Giving Equal Width to Elements
How to Make My Flexbox Layout Take 100% Vertical Space
Two Inline-Block, Width 50% Elements Wrap to Second Line