skip to Main Content

How would I center the title of my web page. Here is my code so far written out on paper:

code written down

I want to center the heading of my title "Libertarian Nation"

The code written out without image:

<!DOCTYPE html>
<html>
<head>
    <title>"Libertarian Nation"</title>
</head>
<body>
    A place of decentralisation
</body>
</html>

So how could I center the title of my page?

3

Answers


  1. you can simply try something like this:

    HTML:

    <h1>A Place of Decentralization</h1>
    

    CSS:

    h1 {
        text-align: center;
    }
    

    This can either go in a separate file or above between <Style> tags.

    Login or Signup to reply.
  2. Although it’s now depreciated (no longer being updated and may break) you can use;

    <Center>
        Title!
    </Center>
    

    An alternative is creating a CSS class for it. For example:

    <Style>
       . center {
            Text-align: center;
       }
    </Style>
    

    This will create a class in CSS called center for convenience. So you can now make your title like this:

    <p class="center">Title!</p>
    

    This should now create a centered title saying Title!

    Please note that<Title> does not make a title on the page itself but is the name visabel on the tab. Please a CSS class or something like <H1> to make your titles or headings for your website.

    Login or Signup to reply.
  3. considering ‘decentralisation’ is the text you wish to bring to centre.
    Keep in mind everything in html is kind of like encapsulated e.g. <body>your text </body> is encapsulated with in body tag. So this relationship is called parent child relationship …an item can have as many grands parent going all the way up to body tag and have as many grand children going all the way down to end of body tag.

    so we will create a child tag.

    <body>
    <p>yourtext</p>
    </body> 
    

    Once we have that then we can apply styling on to it using CSS.

    <p  style="text-align:center;">your text</p>
    

    we haven’t we applied Css on parent or why create encapsulating tag because it would limit the scope other wise things will be applied on all the other children of the parent as well.

    Further links to play around with
    some alignment trickery

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search