i like cows
i like cows

Reputation: 25

how to center text using html and css

I have got some text on my html site using a div tag so I can center the text but it wont center.

This is what I put in the HTML

<div id="info"> 
Welcome
</div>

This is what I put in the CSS

#info {
color: #0F0;
font-size: 20px;
text-align: center;
}

I have used the right css code to center the text but for some reason it wont center. Has anybody got any ideas?

Upvotes: 2

Views: 2244

Answers (4)

Towsef Nafe
Towsef Nafe

Reputation: 1

text-align: center; 

For more details read this: https://www.w3schools.com/cssref/pr_text_text-align.ASP

Upvotes: 0

sonam sharma
sonam sharma

Reputation: 1

Center-align text in an HTML page: Hello

<center>Hello</center>

Upvotes: -1

Duc Huy Ta
Duc Huy Ta

Reputation: 141

It's working fine https://codeide.co/master/LpcINKJK. I think you should check element's width.

#info {
    color: #0F0;
    font-size: 20px;
    text-align: center;
    width: 100%;
}

Upvotes: 0

Niclas Larsson
Niclas Larsson

Reputation: 1317

text-align: center; is correct. Your code should work as expected. Try to validate your site and see if you did any typos or so: https://validator.w3.org/

Upvotes: 4

Related Questions