How to use style="text-align:center;" on the ordinary text?

For now I have used <h1></h1> What to do if I want to center the text without using the header?

2 answers

  • answered 2018-11-07 20:35 Jose Manuel Zuñiga Moreno

    h1{
        text-align: center;
    }
    p{
        text-align: left;
    }
    <h1>My Text<h1/>
    <p>some other text</p>

    You should start using css to code everything about the html properties, not inside the html code

  • answered 2018-11-07 20:37 Roddy of the Frozen Peas

    Text -- regular paragraphs of text -- should be wrapped in paragraph tags (<p></p>). You can then center all p tags (or just the one you're targetting).

    p {
      text-align: center; 
    }
    <h1>I am a heading</h1>
    
    <p>I am regular text</p>

    Alternatively, if you want to center everything, you can style the <body> tag.

    body {
      text-align: center;
    }
    <h1>I am a header</h1>
    <h2>I am a subheader</h2>
    
    I am unwrapped text.
    
    <p>I am text in a paragraph tag.</p>

    Note that putting the style on the body will center everything.

    (Some browsers will implicitly wrap your regular text in <p> tags if you don't, but it's much better practice for you to do it yourself.)