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

Design

Web title

Hi there, I am building a website and I understand how to get a piece of <h1> text to appear, but I don't know how to center it. Any ideas?

Gabriel

3 Answers

James Barnett
James Barnett
39,199 Points

You center inline content with text-align: center and block content with margin: auto.

source: http://dorward.me.uk/www/centre/

If you have any more questions, create a codepen so we can see what you are working with

Thanks!

Marcus Tisäter
Marcus Tisäter
4,886 Points

Depends if she has put in a block or not. Using position center works aswel. It's kind of tricky tho. text-allign: center is the best one to use if there is a block.

James Barnett
James Barnett
39,199 Points

> Using position center works aswel.

Umm ... position:center I don't think that CSS property exists. Or did I misunderstand something?

Marcus Tisäter
Marcus Tisäter
4,886 Points

Position center exists but I reconsider it and it wouldn't be the perfect fit for this question. text-align: center is the way to go

James Barnett
James Barnett
39,199 Points

> Position center exist

Do you have a link? Or some code to show that? Are you thinking of background-position: center by chance.