There are many ways to do the alignment, my recommendation is, don’t.
I know that’s how the example project looks, but most forms have the labels on top of the input. It is not only easier to make, but user tests have shown that your eyes can scan the form quicker. So it is actually considered better UX to have the labels on top.
In any case, here is one way of doing it using Grid.
<form action="">
<div class="personal-info">
<label for="name">Name</label>
<input type="name" id="name" required placeholder=" Enter your name">
<label for="email">Email</label>
<input type="email" id="email" required placeholder=" Enter your email">
<label for="number">Your age</label>
<input type="number" name="number" id="number" min="1" max="125" required placeholder="Enter your age">
</div>
</form>
.personal-info {
display: grid;
grid-template-columns: max-content 1fr;
grid-gap: 20px 10px;
align-items: center;
max-width: 420px;
margin: auto;
}
.personal-info > input {
padding: 10px;
}
.personal-info > label {
/* if you want to right align the labels */
/* justify-self: end; */
}
@lasjorg Thanks mate, looks much better idd!
I love the fact that you pointed out why you don’t recommend doing alignment and referring to the Google AI Blog article! Much appreciated!
I’ll being using Grid in the future.
Again, thanks to the both of you!
At KittyKora I can’t see what you’ve posted. (post withdrawn by autor, (…) unless flagged)
Nonetheless, thank you for taking the time to reply!