Search code examples
html

how to place text left/right in html?


Is it possible to place text in html left and right

I want it to place the text left and right on the same line.

My HTML code:

    <!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>RPG Clicker</title>
        <link rel="stylesheet" type="text/css" href="interface.css" />
    </head>

    <body>
       <left>Level: <span id="level">1</span></left>
       <right>Gon level: <span id="gon">0</span></right>
    </body>
    </html>

Demo


Solution

  • There is no <left> or <right> tag in html. To achieve what you want to do, you will have to do it with CSS.

    .align-left {
      float: left;
      width:33%;
    }
    
    .align-center {
      text-align: center;
      display: inline-block;
      width:34%;
    }
    
    .align-right {
      float: right;
      text-align: right;
      width:33%;
    }
    <html>
      <head>
      </head>
      <body>
        <span class="align-left">Level: <span id="level">1</span></span>
        <span class="align-center">Text</span>
        <span class="align-right">Gon level: <span id="gon">0</span></span>
      </body>
    </html>