<form>
    <fieldset>
        <legend>Enter your name</legend>
        <label for="user-name">Usrname</label>
        <input type="text" id="user-name" placeholder="Enter your name...">
    </fieldset>
</form>
fieldset {
    padding: 1em;
}
fieldset:focus-within {  /* Selected when the element or any of its descendants has focus */
    background-color: yellow;
}
Rendered Output When you focus on the <input> element to enter your name, the ancestor <fieldset> element will have the fieldset:focus-within style applied, changing its background color to yellow.
:focus-within {
    /* ... */
}
<form>
    <fieldset>
        <legend>Contact Information</legend>
        <label for="email">Email</label>
        <input type="email" id="email" placeholder="Enter your email">
    </fieldset>
</form>
fieldset {
    padding: 1em;
    border: 2px solid gray;
    transition: border-color 0.3s ease;
}
fieldset:focus-within {
    border-color: blue;
    background-color: #e6f0ff;
}
Rendered Output
<div class="card" tabindex="0">
    <h3>Product Title</h3>
    <p>Short description of the product.</p>
    <button>Learn More</button>
</div>
<div class="card" tabindex="0">
    <h3>Another Product</h3>
    <p>Another short description.</p>
    <button>Learn More</button>
</div>
.card {
    border: 1px solid #ccc;
    padding: 1em;
    margin: 1em 0;
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    outline: none;
}
.card:focus-within {
    border-color: #007acc;
    box-shadow: 0 0 10px #007acc;
}
Rendered Output