Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:58:18+00:00 2026-06-13T20:58:18+00:00

I’m new to CSS and have a simple login form that I’m trying to

  • 0

I’m new to CSS and have a simple login form that I’m trying to align correctly. Basically two columns with the labels and the Login button in one column and the text boxes in another column. How do I do this in CSS?

The HTML code is:

<body>
  <form action="" method="post">
    <label> Username </label>
    <input type="text"/>

    <label> Password </label>
    <input type="password"/>

    <input type="submit" value="submit"/>
  </form>
</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:58:19+00:00Added an answer on June 13, 2026 at 8:58 pm

    This is one approach that works:

    form {
      width: 80%;
      margin: 0 auto;
    }
    
    label,
    input {
      /* In order to define widths */
      display: inline-block;
    }
    
    label {
      width: 30%;
      /* Positions the label text beside the input */
      text-align: right;
    }
    
    label+input {
      width: 30%;
      /* Large margin-right to force the next element to the new-line
               and margin-left to create a gutter between the label and input */
      margin: 0 30% 0 4%;
    }
    
    
    /* Only the submit button is matched by this selector,
           but to be sure you could use an id or class for that button */
    
    input+input {
      float: right;
    }
    <form action="#" method="post">
      <!-- note that I've added a 'for' attribute to
           both of the <label> elements, which is
           equal to the 'id' attribute of the relevant
           <input> element; this means that clicking
           the <label> will focus the <input>: -->
      <label for="username">Username</label>
      <input id="username" type="text" />
    
      <label for="password">Password</label>
      <input id="password" type="password" />
    
      <input type="submit" value="submit" />
    </form>

    ​

    JS Fiddle demo.

    Adjust dimensions and margins to suit your use-case and aesthetic of course.

    Of course, currently, there are other means by which this can work, such as CSS Grid:

    *,
    ::before,
    ::after {
      /* selecting all elements on the page, along with the ::before
         and ::after pseudo-elements; resetting their margin and
         padding to zero and forcing all elements to calculate their
         box-sizing the same way, 'border-box' includes the border-widths,
         and padding, in the stated width: */
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    form {
      /* Using CSS Grid to lay out the elements in two-dimensions: */
      display: grid;
      /* specifying a 0.5em gutter/gap between adjacent elements: */
      gap: 0.5em;
      /* declaring a number of named grid areas in order to lay out
         the child elements; the areas identified with a period (.)
         are 'empty' areas, whereas the areas named by strings are
         used, later, to place elements according to those names: */
      grid-template-areas:
        "usernameLabel . usernameInput"
        "passwordLabel . passwordInput"
        ". . submit";
      /* declaring the size of each of the three columns; 1fr is
         one fractional unit of the available space, and is the
         size of the first and last of the columns. The central
         column is declared as being 0.5em in width: */
      grid-template-columns: 1fr 0.5em 1fr;
      margin: 1em auto;
      width: 80%;
    }
    
    label {
      /* placing all <label> elements in the grid column 1 (the first): */
      grid-column: 1;
      /* aligning text-content to the right in order to position the label
         text near to the relevant <input>: */
      text-align: right;
    }
    
    label::after {
      content: ':';
    }
    
    input {
      grid-column: 3;
    }
    
    button {
      /* positioning the <button> element in the grid-area identified
         by the name of 'submit': */
      grid-area: submit;
    }
    <form action="" method="post">
      <label for="username">Username</label>
      <input id="username" type="text" />
    
      <label for="password">Password</label>
      <input id="password" type="password" />
    
      <input type="submit" value="submit" />
    </form>

    JS Fiddle demo.

    References:

    • Adjacent-sibling (+) combinator.
    • box-sizing.
    • display.
    • float.
    • gap.
    • grid-area.
    • grid-template-areas.
    • grid-template-columns.
    • grid-template-rows.
    • margin.
    • width.

    Bibliography:

    • "Basic Concepts of grid layout."
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.