Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Last active September 18, 2022 12:59
Show Gist options
  • Save DJStompZone/99e84c6198db753d2a7dcfb214775c2a to your computer and use it in GitHub Desktop.
Save DJStompZone/99e84c6198db753d2a7dcfb214775c2a to your computer and use it in GitHub Desktop.
This form :has whimsical touches ✨
<html>
<head>
<link href="https://gist.githubusercontent.com/DJStompZone/99e84c6198db753d2a7dcfb214775c2a/raw/d1bb4e55a78bc553b55d9a6601fdc77f7be3329d/style.css" rel="stylesheet" />
<link href="https://unpkg.com/open-props/colors-hsl.min.css" rel="stylesheet" />
<link href="https://unpkg.com/open-props/open-props.min.css" rel="stylesheet" />
<link href="https://unpkg.com/open-props/normalize.min.css" rel="stylesheet" />
</head>
<body>
<form action="">
<div class="form-group">
<label for="email" class="form-label">
<span aria-hidden="true" class="label__letter" style="--index: 0;">E</span>
<span aria-hidden="true" class="label__letter" style="--index: 1;">m</span>
<span aria-hidden="true" class="label__letter" style="--index: 2;">a</span>
<span aria-hidden="true" class="label__letter" style="--index: 3;">i</span>
<span aria-hidden="true" class="label__letter" style="--index: 4;">l</span>
<span class="sr-only">Email</span>
</label>
<input required type="email" id="email" class="form-input" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" title="Enter valid email address" placeholder="Enter valid email address"/>
</div>
<div class="form-group">
<label for="password" class="form-label">
<span aria-hidden="true" class="label__letter" style="--index: 0;">P</span>
<span aria-hidden="true" class="label__letter" style="--index: 1;">a</span>
<span aria-hidden="true" class="label__letter" style="--index: 2;">s</span>
<span aria-hidden="true" class="label__letter" style="--index: 3;">s</span>
<span aria-hidden="true" class="label__letter" style="--index: 4;">w</span>
<span aria-hidden="true" class="label__letter" style="--index: 5;">o</span>
<span aria-hidden="true" class="label__letter" style="--index: 6;">r</span>
<span aria-hidden="true" class="label__letter" style="--index: 7;">d</span>
<span class="sr-only">Password</span>
</label>
<input required type="password" id="password" class="form-input" pattern=".{8,}" title="Enter password (8+ characters)" placeholder="Enter password"/>
</div>
<button type="submit">Submit</button>
</form>
</body>
</html>
*,
*:after,
*:before {
box-sizing: border-box;
}
:root {
--red: hsl(18 100% 50%);
--green: hsl(130 52% 46%);
--yellow: hsl(44 83% 53%);
--blue: hsl(215 100% 53%);
--grey: hsl(0 0% 45%);
--text: var(--gray-5);
--transition: 0.2s;
--valid: var(--green);
--invalid: var(--red);
--focus: var(--yellow);
--blur: var(--blue-1);
--disabled: var(--grey);
}
:where(html) {
color-scheme: none;
}
body {
display: grid;
min-height: 100vh;
font-family: 'Google Sans', sans-serif, system-ui;
place-items: center;
overflow: hidden;
margin: 0;
background-color: transparent;
font-size: 1rem;
}
form {
display: grid;
grid-gap: 1rem;
}
input {
border: 4px solid var(--color);
border-radius: 4px;
padding: 1rem 2rem;
font-weight: 400;
transition: border-color var(--transition);
}
input:focus-visible {
outline-color: var(--color);
}
input::placeholder {
color: transparent;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
.form-group {
display: flex;
align-items: center;
justify-content: flex-end;
}
label {
font-family: sans-serif;
display: flex;
font-weight: bold;
padding-right: 1rem;
transform-style: preserve-3d;
transition: color var(--transition);
color: var(--color);
font-size: 1.25rem;
}
button {
padding: 1rem 2rem;
border-radius: 4px;
border: 0;
cursor: pointer;
background: var(--disabled);
font-weight: bold;
color: var(--gray-5);
transition: color var(--transition), background var(--transition);
}
.form-group:has(:invalid) {
--color: var(--invalid);
}
.form-group:has(:invalid:not(:focus)) {
animation: shake 0.65s;
}
.form-group:has(:focus) {
--color: var(--focus);
}
.form-group:has(:valid) {
--color: var(--valid);
}
.form-group:has(:valid) span {
animation: twirl 1s calc(var(--index) * 0.1s);
}
.form-group:has(:placeholder-shown) {
--color: var(--blur);
}
.form-group:has(:placeholder-shown:not(:focus)) {
animation: none;
}
label span {
display: inline-block;
}
form:valid [type="submit"] {
background: var(--valid);
color: var(--gray-1);
}
@keyframes twirl {
100% {
transform: rotateY(360deg);
}
}
@keyframes shake {
0%, 100% {
transform: translateX(0);
}
20%, 40%, 60%, 80% {
transform: translateX(-2%);
}
10%, 30%, 50%, 70%, 90% {
transform: translateX(2%);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment