// See HTMLFormControlsCollection in post
// Reference the form tag
var card = document.forms.card;
// Reference all form controls of form tag
var ui = card.elements;
// Register the ALL checkbox (input#c0) to the change event
ui.c0.addEventListener('change', chxAll);
// Callback function passes Event Object
function chxAll(e) {
// Declare increment counter outside of loop
var c = 1;
// Ternary checks to see if input#c0 is checked
var all = e.target.checked ? true : false;
// Loop thruogh the next 4 inputs...
for (c; c < 5; c++) {
// Check/uncheck each checkbox in ui HTMLCollection
ui[c].checked = all;
}
// Open the details tag (optional)
document.querySelector('.options').open = true;
}
html,
body {
font: 400 16px/1.2 Consolas;
font-variant: small-caps;
width: 100%;
height: 100%;
}
.chx {
display: none
}
.lab {
display: inline-block;
margin: 10px;
cursor: pointer;
}
.lab::before {
content: '\1f518';
box-shadow: 0px 1.5px 1px 2.5px rgba(51, 51, 51, 0.3);
border-radius: 50%;
}
#c1:checked~.header .options .c1::before,
#c2:checked~.header .options .c2::before,
#c3:checked~.header .options .c3::before,
#c4:checked~.header .options .c4::before {
content: '\1f535';
box-shadow: 0px 1.5px 1px 2.5px rgba(15, 102, 241, 0.5);
}
#c0:checked~.header .c0::before,
#c0:checked+#c1:checked~.header .options .c1::before,
#c0:checked~#c2:checked~.header .options .c2::before,
#c0:checked~#c3:checked~.header .options .c3::before,
#c0:checked~#c4:checked~.header .options .c4::before {
content: '\1f534';
box-shadow: 0px 1.5px 1px 2.5px rgba(241, 102, 15, 0.5);
}
#c1:checked+#c2:checked+#c3:checked+#c4:checked+.header .c0::after {
content: ' Selected';
color: rgba(15, 102, 241, 1);
text-shadow: 1.5px 2px 1.75px rgba(15, 102, 241, 0.7);
}
#c0:checked+#c1:checked+#c2:checked+#c3:checked+#c4:checked+.header.header .c0::after {
content: ' Selected';
color: rgba(241, 102, 15, 1);
text-shadow: 1.5px 2px 1.75px rgba(241, 102, 15, 0.7);
}
#c1:not(:checked)~.header .c0::after,
#c2:not(:checked)~.header .c0::after,
#c3:not(:checked)~.header .c0::after,
#c4:not(:checked)~.header .c0::after {
content: '';
}
#c1:not(:checked)~.header .c0::before,
#c2:not(:checked)~.header .c0::before,
#c3:not(:checked)~.header .c0::before,
#c4:not(:checked)~.header .c0::before {
content: '\1f518';
box-shadow: 0px 1.5px 1px 2.5px rgba(51, 51, 51, 0.3);
}
.header {
border: 3px inset rgba(51, 51, 51, 0.51);
border-radius: 5px;
-webkit-padding-before: 0.0em;
-webkit-padding-start: 0.15em;
-webkit-padding-end: 0.15em;
-webkit-padding-after: 0.15em;
box-shadow: 0px 1.5px 1px 2.5px rgba(51, 51, 51, 0.3);
width: 380px;
}
legend {
height: 35px
}
legend h3 {
font-size: 1.55rem;
line-height: 2;
transform: translateY(-35px);
}
.options {
background: rgba(3, 9, 27, 0.1);
border: 3px inset rgba(51, 51, 51, 0.15);
border-radius: 5px;
box-shadow: 0px -2px -1px 0px rgba(51, 51, 51, 0.15);
}
summary {
padding: 3px 5px;
font-size: 1.2rem;
cursor: pointer;
}
<form id='card'>
<input type="checkbox" class="chx" id="c0" />
<input type="checkbox" class="chx" id='c1' />
<input type="checkbox" class="chx" id='c2' />
<input type="checkbox" class="chx" id='c3' />
<input type="checkbox" class="chx" id='c4' />
<fieldset class='header' name="header">
<legend>
<h3>List of Checkboxes</h3>
</legend>
<label for='c0' class='c0 lab'> All Options</label>
<details class="options">
<summary>Select Options</summary>
<label for='c1' class='c1 lab'> One </label>
<label for='c2' class='c2 lab'> Two </label>
<label for='c3' class='c3 lab'> Three </label>
<label for='c4' class='c4 lab'> Four </label>
</details>
</fieldset>
</form>