Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Joshcanread

How to center heading in HTML

Recommended Posts

Posted · Original PosterOP

I'm on this shitty website called "Grok" to learn how to code and its like "center the heading" and if I use the <center> thing its like yo you cant do thats its illegal. It wants me to make the Left and Right margins in the style like this

}
h1 {
  line-height: 1.6;
   margin-left: auto;
    margin-right: auto;

}

It works for the P that I have under it but with the h1 it just doesn't want to work

Link to post
Share on other sites
3 minutes ago, Joshcanread said:

I'm on this shitty website called "Grok" to learn how to code and its like "center the heading" and if I use the <center> thing its like yo you cant do thats its illegal. It wants me to make the Left and Right margins in the style like this

}
h1 {
  line-height: 1.6;
   margin-left: auto;
    margin-right: auto;

}

It works for the P that I have under it but with the h1 it just doesn't want to work

Well it kinda depends on the rest of the webpage you're doing it in.

 

For example:

<style>
  .container {
    display: flex;
    justify-content: center;
	align-items: center;
  }
</style>

<div class="container">
  <h1>Test123</h1>
</div>

Would work. Or:

 

<style>
  .container>h1 {
    margin: 0 auto;
  }
</style>

<div class="container">
  <h1>Test123</h1>>
</div>

 

should kinda do the same thing. Can we get some more inf? :P


75% of what I say is sarcastic

 

So is the rest probably

Link to post
Share on other sites
Posted · Original PosterOP
3 minutes ago, myselfolli said:

Well it kinda depends on the rest of the webpage you're doing it in.

 

For example:


<style>
  .container {
    display: flex;
    justify-content: center;
	align-items: center;
  }
</style>

<div class="container">
  <h1>Test123</h1>
</div>

 Would work. Or:

 


<style>
  .container>h1 {
    margin: 0 auto;
  }
</style>

<div class="container">
  <h1>Test123</h1>>
</div>

 

should kinda do the same thing. Can we get some more inf? :P

yeah it doesn't like it at all I will DM you all the info

Link to post
Share on other sites
Posted (edited)
text-align: center;

You can either set this to the h1 or the container

Edited by duncannah

Link to post
Share on other sites

Pro tip for trying to get shit aligned in html:  make sure all sharp objects are out of arm's reach.  You will be tempted to use them on yourself.

image.png.47c0528dd1399e5419b982cf2e4b64cb.png

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×