<p class="support">⚠️ Your browser does not support the CSS <code>:has()</code> selector so this demo won't work. Please try Safari TP 137.</p>
<form>
  <h1>Email Newsletter</h1>
  <input type="email" placeholder="Enter your email!" required />
  <label for="checkbox">
    <input type="checkbox" id="checkbox">
    Agree to the agreement!
  </label>
  <button class="button">Enter</button>
</form>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  display: grid;
  gap: 1.25rem;
  line-height: 1.5;
  place-content: center;
}

.support {
  color: #842029;
  background-color: #f8d7da;
  padding: 1rem 1rem;
  border: 1px solid #f5c2c7;
  border-radius: 0.25rem;
  font-size: 1rem;
  grid-column: 1 / -1;
}

@supports (selector(:has(*))) {
  .support {
    display: none;
  }
}

:root {
  --color-primary: #2eec96;
  --selection-color: #abffd9;
  --unitless-max-font-size: 18;
  --color-error: #f44336;
  --border-color: #bfbfbf;
  --button-color: var(--color-primary);
  --button-text-color: rgb(0, 25, 80);
}

form {
  max-width: 30rem;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  color: #000;
  gap: 1rem;
}

form h1 {
  margin: 0;
  font-size: var(--font-size-3);
  text-align: center;
  color: #000;
}

input[type="email"] {
  display: inline-flex;
  align-items: center;
  width: 100%;
  min-height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border-color);
  color: var(--text-color);
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 0.75rem;
}

input[type="email"]:valid {
  border-color: var(--color-primary);
  background-image: url("data:image/svg+xml,%3Csvg width='45px' height='34px' viewBox='0 0 45 34' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg transform='translate%28-56.000000, -59.000000%29' fill='%232EEC96'%3E%3Cpolygon points='70.1468531 85.8671329 97.013986 59 100.58042 62.5664336 70.1468531 93 56 78.8531469 59.5664336 75.2867133'%3E%3C/polygon%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A");
}

input[type="email"]:invalid {
  border-color: var(--color-error);
  background-image: url("data:image/svg+xml,%3Csvg width='30px' height='30px' viewBox='0 0 30 30' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg transform='translate%28-128.000000, -59.000000%29' fill='%23F44336'%3E%3Cpolygon points='157.848404 61.9920213 145.980053 73.8603723 157.848404 85.7287234 154.856383 88.7207447 142.988032 76.8523936 131.119681 88.7207447 128.12766 85.7287234 139.996011 73.8603723 128.12766 61.9920213 131.119681 59 142.988032 70.8683511 154.856383 59'%3E%3C/polygon%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A");
}

input:invalid:focus {
  border-color: var(--color-error);
}

label[for="checkbox"] {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.button {
  display: flex;
  border: none 0;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  border-radius: 4px;
  background-color: var(--button-color);
  color: var(--button-text-color);
  font-family: "Exo", Arial, sans-serif;
  font-size: 1.25rem;
}

.button {
  --button-color: hsl(0, 0%, 90%);
  --button-text-color: hsl(0, 0%, 50%);
  cursor: not-allowed;
}
form:has(input[type="checkbox"]:checked) .button {
  --button-color: var(--color-primary);
  --button-text-color: rgb(0, 25, 80);
  cursor: pointer;
}

form:has(input[type="checkbox"]:checked) .button:hover {
  --button-text-color: rgb(0, 25, 80);
  --button-color: #2eec96e3;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.