Take the 2-minute tour ×

Forgive me for asking such a simple question, I'm new to both HTML and CSS. Is there an easy way to center a textarea? I figured I'd just try using

    margin-left: auto;
    margin-right: auto;

but it (obviously?) didn't work.

Help would be much appreciated :-)

share|improve this question

4 Answers 4

up vote 35 down vote accepted

The margins won't affect the textarea because it is not a block level element, but you can make it display block if you like:

    display: block;
    margin-left: auto;
    margin-right: auto;

before and after

By default, textareas are display: inline, which is why you can put them side-by-side easily, and why the text-align: center answers work too.

share|improve this answer
This is what I'm using now, do you know if there's anything bad about it (as it sounds too easy to be true/good ;-) )? –  Chris Aug 26 '10 at 22:48
Nope, I don't know of any downsides. –  Douglas Aug 26 '10 at 22:50
One downside is when textarea is resized, (by dragging resize-handle), it is no longer adjusted to center. (At least on Chrome). –  Sukminder Nov 30 '13 at 3:02

Set text-align of the element's parent to center, like this:




div { text-align: center; }

Here is an example: http://jsfiddle.net/ujzLt/

share|improve this answer
Thank you for your quick reply! I have already assigned some colors and other things to the div element though, how do I get one which only has text-align:center;? –  Chris Aug 26 '10 at 22:40
@Chris -- just add text-align:center; to your current <div>'s css declaration then. :-) –  Sean Vieira Aug 26 '10 at 22:47
You can add all styling to the same div (color, font-family, text-align,...) or isn't this what you mean? –  davehauser Aug 26 '10 at 22:50
I actually wanted to remove the styles from the div so they wouldn't apply to the textarea, but perhaps that isn't needed (thought it would form a box with background color and padding, like my div does)? –  Chris Aug 26 '10 at 23:29
They do not apply to the textarea, you can leave them as they are. –  davehauser Aug 26 '10 at 23:32

add display: block; to your textarea styles

share|improve this answer
Hey that did the trick, combined with the styles I already had, like you said. Thanks! –  Chris Aug 26 '10 at 22:46
No problem, sometimes it's the simple things that work best. –  Jeff Adams Aug 26 '10 at 22:47
<title>Untitled Document</title>
<style>#container {width:100%; text-align:center;}</style>

<div id="container">
<textarea name="mytextarea" cols="10" rows="10"></textarea>

you wrap your textarea with a div, give it width and then you align it with text-align:center;

share|improve this answer
Thanks a lot :-)! However, like I explained above, I have already made my div prettier, how do I get back to a default one with just the text align? –  Chris Aug 26 '10 at 22:40

Your Answer


