Form error messages styles | Bouncing input labels styles

PHOTO EMBED

Sun Mar 20 2022 18:08:42 GMT+0000 (Coordinated Universal Time)

Saved by @max_demydenko #css #form

/*CSS*/
.field-item__wrapper {
    position: relative;
    padding-top: 15px;
}
.form__field {
    font-family: inherit;
    width: 100%;
    border: 0;
    border-bottom: 2px solid #000;
    outline: 0;
    color: #000;
    padding: 7px 0;
    background: 0 0;
    transition: border-color 0.2s;
}
.form__field::placeholder {
    color: transparent;
    opacity: 0;
}
.form__field:placeholder-shown ~ .form__label {
    cursor: text;
    top: 20px !important;
}
.form__label {
    position: absolute;
    top: 0;
    display: block;
    transition: 0.2s;
    color: #000;
}
.form__field:focus {
    padding-bottom: 6px;
    border-width: 3px;
    border-image-slice: 1;
    border-color: #000 !important;
}
.form__field:focus ~ .form__label {
    position: absolute;
    top: 0 !important;
    font-size: 0.8em;
    display: block;
    transition: 0.2s;
}
.form__field:invalid,
.form__field:required {
    box-shadow: none;
}
.w-input.error {
    border-color: #cc3131;
}
label.error {
    font-size: 10px;
    line-height: 24px;
    color: #cc3131;
    position: absolute;
    bottom: -25px;
}
/*CSS*/
content_copyCOPY

When the input is not touched label is inside the field. When the input is touched or there is some values inside it the label is above the field with reduced font-size NOTES: - field-item__wrapper is a class for div that wraps input and label tags - form__field is a class of input element - form__label is a class of label element IMPORTANT: - To make this code work properly you should have a wrapper for input and label tags and equal name (in input tag) with for (in label tag) attributes - Also you should have the same field placeholder as this field label

https://agency-website-c0d1e7.webflow.io/