Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Fedor Andreev
Fedor Andreev
6,438 Points

How would you center a textarea with css?

The code for html

<textarea cols="40" rows="8" name="textarea"></textarea>

But I've looked everywhere on google and no code allows me to center it on the page with css? I've tried everything, and converting it to a block. Can someone write me a code for css that allows it to be centered? Perhaps something is wrong with my html code? (can't be I can see and click the textarea on my page).

Help!!

Stone Preston
Stone Preston
42,016 Points

you will need to format your code using markdown to get html code to show up in forum posts. there is a link to a markdown cheatsheet at the bottom right corner of the post/comment box that explains how to format it.

3 Answers

Stone Preston
Stone Preston
42,016 Points

hard to say without looking at your code, but have you tried setting the left and right margins of it to auto and setting its display property to block?

textarea{
    display: block;
    margin-left: auto;
    margin-right: auto;
}

text-areas are inline by default, so simply setting the margins wont work. you have to make it a block element as well.

Fedor Andreev
Fedor Andreev
6,438 Points
   textarea{
    display: block;
    margin-left: auto;
    margin-right: auto;
}

```<textarea cols="40" rows="8" name="textarea"></textarea>
            ``` 
Fedor Andreev
Fedor Andreev
6,438 Points

It's still on the left side :(

Stone Preston
Stone Preston
42,016 Points

its hard to tell what exactly is going on in your code blocks. its not formatted quite right. to format a code block you need to skip a line, type 3 backticks (they are below the escape key) then on a new line post your code, then on a new line type 3 more back ticks