skip to Main Content

I have a big question, I am starting with HTML and I saw that to center a title I can use

<h1 style="text-aline: center;"></h1>

and I can also use

<h1 align ="center"></h1>

which method is more recommended and what is the difference between these

I am learning and I want to start with good foundations

3

Answers


  1. The best practice for centering a title is to do it in CSS (with the style attribute)

    <h1 style="text-align:center;">Centered Text</h1>
    Login or Signup to reply.
  2. You can use the center tag to center the title of using html
    example

        <center> <h1>Your data </h1></center>
    
        <div style="text-align: center;">
            <h1>This is Title </h1>
        </div> 
    

    If you are using inline css that can same work.

    Example of inline CSS:

    <div style="text-align: center;">
        <h1>Your text is center </h1>
    </div> 
    

    You can learn in depth of html

    Resources: w3school

    Login or Signup to reply.
  3. It would be best to use text-align: center. Aligning things with HTML attributes is generally not best practice, it’s better to use CSS to align things.

    I’d also recommend moving your CSS to either a <style> tag or a separate CSS file to improve the readability of your HTML markup. For example

    <h1 class="center">Some text</h1>
    
    <style>
    .center {
      text-align: center;
    }
    </style>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search