<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> label{ float: left; margin: 0 5px; overflow: hidden; position: relative; } label input{ position: absolute; top: -50px; left: -50px; } span{ float: left; width: 50px; height: 50px; border: 3px solid #000; } input:checked ~ span{ background-color: red; } </style> </head> <body> <label> <input type="radio" name="tab"> <span></span> </label> <label> <input type="radio" name="tab"> <span></span> </label> <label> <input type="radio" name="tab"> <span></span> </label> </body> </html>