<h1>Demo: Style placeholder text</h1>
<div>
  <input type="checkbox" id="apply-styling-checkbox" />
  <label for="apply-styling-checkbox">Apply styling with ::placeholder pseudo-class</label>
</div>
<h2>Fill out this form</h2>
<form>
  <div class="form-field">
    <label for="fav-food">Favorite Food:</label>
    <input type="text" id="fav-food" placeholder="Pizza, pasta, ..." />
  </div>
  <div class="form-field">
    <label for="fav-animal">Favorite Animal:</label>
    <input type="text" id="fav-animal" placeholder="Cat, dog, horse, ..." />
  </div>
</form>
body:has(input#apply-styling-checkbox:checked) input::placeholder {
  color: #7263B6;
  font-style: italic;
}

form {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.5rem;
  width: fit-content;
  font-family: sans-serif;
  font-size: 0.9rem;
  
  .form-field {
    grid-column: span 2;
    display: grid;
    grid-template-columns: subgrid;
    align-items: center;
  }
  
  label {
    font-weight: bold;
  }
  
  input {
    font-size: 0.938rem;
    padding: 0.25rem;
    border: 0.125rem solid rebeccapurple;
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.