Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <style> .checkbox-container { max-width: 400px; margin: 40px auto; padding: 30px; background-color: #f9f9f9; border-radius: 8px; font-family: sans-serif; } .checkbox-container h3 { margin-top: 0; } /* The container for each option */ .checkbox-option { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 1rem; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* Hide the browser's default checkbox */ .checkbox-option input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; } /* Create a custom checkbox */ .checkmark { position: absolute; top: 0; left: 0; height: 22px; width: 22px; background-color: #eee; border: 1px solid #ccc; border-radius: 4px; transition: background-color 0.2s; } /* On mouse-over, add a grey background color */ .checkbox-option:hover .checkmark { background-color: #ccc; } /* When focused with keyboard, show a focus ring */ .checkbox-option input:focus ~ .checkmark { box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.5); border-color: #007bff; } /* When the checkbox is checked, add a blue background */ .checkbox-option input:checked ~ .checkmark { background-color: #007bff; border-color: #007bff; } /* Create the checkmark/indicator (hidden when not checked) */ .checkmark:after { content: ""; position: absolute; display: none; } /* Show the checkmark when checked */ .checkbox-option input:checked ~ .checkmark:after { display: block; } /* Style the checkmark/indicator */ .checkbox-option .checkmark:after { left: 7px; top: 3px; width: 5px; height: 10px; border: solid white; border-width: 0 3px 3px 0; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } </style> <div class="checkbox-container"> <h3>Choose Your Toppings:</h3> <div class="checkbox-option"> <input type="checkbox" id="topping-lettuce" checked="checked"> <label for="topping-lettuce">Lettuce</label> <span class="checkmark"></span> </div> <div class="checkbox-option"> <input type="checkbox" id="topping-tomato"> <label for="topping-tomato">Tomato</label> <span class="checkmark"></span> </div> <div class="checkbox-option"> <input type="checkbox" id="topping-cheese"> <label for="topping-cheese">Cheese</label> <span class="checkmark"></span> </div> </div>