Solution 1 :

You can apply a display: flex; to the form element.

label{
    display: inline-block;
    float: left;
    clear: left;
    width: 250px;
    text-align: left;
}
input {
  display: inline-block;
  float: left;
}
<form action="contact.html" method="GET">
    <div>
        <label for="fname">Firstname</label>
        <input type="text" id="fname" name="firstname" placeholder="Write your name..">
    </div>
    <div>
        <label for="lname">Lastname</label>
        <input type="text" id="lname" name="lastname" placeholder="Write your lastname..">
    </div>
    

</form>

Solution 2 :

I think you’re looking for a table display that is row-aligned and column-aligned with content

form {
  display: table;
}

div {
  display: table-row;
}

label {
  display: table-cell;
}

input {
  display: table-cell;
}
<form action="contact.html" method="GET">
  <div class="flexbox">
    <label for="fname">Firstname</label>
    <input type="text" id="fname" name="firstname" placeholder="Write your name..">
  </div>
  <div class="flexbox">
    <label for="lname">Lastname Testing</label>
    <input type="text" id="lname" name="lastname" placeholder="Write your lastname..">
  </div>


</form>

Problem :

I’ve just started to delve into forms. To my understanding so far is that everything that is inside the form tags align horizontally by default, which rises the question:

How do i make my form inputs/items align vertically?

This is the code a simple example:

<form action="contact.html" method="GET">
    <div>
        <label for="fname">Firstname</label>
        <input type="text" id="fname" name="firstname" placeholder="Write your name..">
    </div>
    <div>
        <label for="lname">Lastname</label>
        <input type="text" id="lname" name="lastname" placeholder="Write your lastname..">
    </div>
    

</form>

By making divs the labels and input started to be on top of eachother instead of next to eachother, which is exactly what i want. But obviously it looks very sloppy with the textareas. They are like glued together, and doesn’t match perfectly at all in position.

Any ideas how i can fix this in CSS?

Best regards!

UPDATE
enter image description here

Clarification: You see how the input areas are completely off. I want those to be EXACTLY perfectly even and matched, so it doesn’t look as scuffed as it does currently.

UPDATE 2: Fix
I figured it out. Now it’s all even and vertical (Though im not saying this is best or the perfect solution, but it solved my current beginner issue/question).

CSS:

form {
    width: 10%;
}

enter image description here

UPDATE 3
Proper solution in the answer feed by Nick Vu. Thread closed.

Comments

Comment posted by css-tricks.com/snippets/css/a-guide-to-flexbox

Welcome to stackoverflow and welcome to web design 🙂 the easiest fix is to add a width to your labels (and some margins) but this isn’t really long lived. I suggest you have a look at either css-grid or flexbox: To learn flexbox i suggest the following two sites:

Comment posted by dokgu

Not sure I understand you correctly but did you want the

Comment posted by Diego D

Or just as a side note, just an humble suggestion, when you’ll be good enough mastering css concepts (flex/grid/display:inline) you could rely on a css framework like bootstrap that will deal with those details in your behalf.

Comment posted by isherwood

FYI, you don’t have an textareas here. That’s a different type of element. You simply have text inputs.

Comment posted by BeerusDev

Copy that, please see my edit

Comment posted by Nick Vu

@Leon my answer did not help you? 🙁

By