<form class="form">
  <div class="form__input-container form__input-container--text">
    <input type="text" class="form__input form__input--text" id="firstname" name="firstname" placeholder=" " />
    <label class="form__label form__label--text" for="firstname">First name: </label>
  </div>
  <div class="form__input-container form__input-container--text">
    <input type="text" class="form__input form__input--text" id="lastname" name="lastname" required placeholder=" " />
    <label class="form__label form__label--text" for="lastname">Last name: </label>
  </div>
  <div class="form__input-container form__input-container--text">
    <input type="email" class="form__input form__input--text" id="email" name="email" required placeholder=" " />
    <label class="form__label form__label--text" for="email">Email: </label>
  </div>
  <div class="form__input-container form__input-container--radio">
    <legend>Favourite animal:</legend>
    <input type="radio" class="form__input form__input--radio" id="meerkats" name="animals" />
    <label class="form__label form__label--radio" for="meerkats">Meerkats</label>
    <input type="radio" class="form__input form__input--radio" id="giraffes" name="animals" />
    <label class="form__label form__label--radio" for="giraffes">Giraffes</label>
    <input type="radio" class="form__input form__input--radio" id="elephants" name="animals" />
    <label class="form__label form__label--radio" for="elephants">Elephants</label>
  </div>
  <button class="form__button">Send</button>
</form>
$transition-time: 0.4s;
$transition-bezier: cubic-bezier(0.75, 0, 0.25, 1);

* {
  margin: 0;
  box-sizing: border-box;
  font-family: HelveticaNeue, Helvetica, Open Sans, sans-serif;
  font-size: 1rem;
}

.form {
  padding: 4rem;
  @media (max-width: 500px) {
    padding: 2rem
}
  &__input-container {
    position: relative;
    padding-top: 20px;
    & + & {
      margin-top: 10px;
    }
    &--text {
      display: flex;
      flex-direction: row-reverse;
      border-bottom: 2px solid #010101;
    }
  }
  &__input {
    font-size: inherit;
    border: none;
    background: none;
    box-shadow: none;
    flex-grow: 1;
    &:focus {
      outline: none;
    }
    &--text {
      transition: flex-grow ($transition-time * 2) $transition-bezier;
      border-bottom: transparent 2px solid;
      padding: 10px 20px;
      &:placeholder-shown:not(:focus) { 
        // enhancements not features:
        & + label {
          position: static;
          padding: 10px 20px;
          font-size: 1rem;
        }
      }
      &:not(:placeholder-shown):not(:focus) {
        // only show the error when the field is not empty and not focused
        &:invalid {
          border-bottom: red 2px solid;
        }
        &:valid {
          border-bottom: #8bc34a 2px solid;
        }
      }
    }
    &--radio {
      opacity: 0;
      width: 0;
      height: 0;
      padding: 0;
      &:checked {
        & + label {
          &::after {
            left: 0.3rem;
            background: black;
          }          
        }
      }
    }
  }
  &__label {
    &--text {
      white-space: nowrap;
      font-weight: bold;
      position: absolute;
      top: 0;
      left: 0;
      display: block;
      font-size: 12px;
      padding: 5px 20px;
      transition: font-size $transition-time $transition-bezier,
        padding $transition-time $transition-bezier;
    }
    &--radio {
      position: relative;
      display: block;
      padding-left: 30px;
      border-radius: 1rem 0 0 1rem;
      overflow: hidden;
      border: 2px solid transparent;
      // we're actually replacing the input with a fake input!
      &::before, &::after {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        margin-left: 1px;
      }
      &::before {
        width: 1rem;
        height: 1rem;
        border: 1px solid black;
        border-radius: 50%;
      }
      &::after {
        width: 0.5rem;
        height: 0.5rem;
        background: transparent;
        border-radius: 50%;
        top: 5px;
        left: -10px;
        transition: left $transition-time $transition-bezier, background $transition-time;
      }
    }
  }
  &__button {
    padding: 10px 20px;
    border: none;
    background: black;
    color: white;
    margin-top: 20px;
    font-size: inherit;
    cursor: pointer;
    transition: $transition-time $transition-bezier;
    &:hover {
      transform: scale(1.05);
    }
  }
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.