Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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