Toggle navigation
☰
HTML
CSS
Scripting
Database
<!doctype html> <title>Example</title> <svg width="80" height="80" viewBox="0 0 100 100" role="img" aria-labelledby="iconTitle iconDesc" id="menuIcon"> <title id="iconTitle">Menu Toggle</title> <desc id="iconDesc">A hamburger menu icon that morphs into an X when clicked to indicate an open state.</desc> <style> .icon-container { cursor: pointer; } .line { fill: none; stroke: #333; stroke-width: 8; stroke-linecap: round; transition: transform 0.3s ease, opacity 0.3s ease; transform-origin: center; } /* Simple hover animation: move slightly */ .icon-container:hover .line-1 { transform: translateY(-2px); } .icon-container:hover .line-3 { transform: translateY(2px); } </style> <!-- Overlayed Triggers for On/Off --> <rect id="iconOn" width="100" height="100" fill="transparent" class="icon-container"> <set attributeName="display" to="none" begin="iconOn.click" /> <set attributeName="display" to="block" begin="iconOff.click" /> </rect> <rect id="iconOff" width="100" height="100" fill="transparent" class="icon-container" display="none"> <set attributeName="display" to="none" begin="iconOff.click" /> <set attributeName="display" to="block" begin="iconOn.click" /> </rect> <g pointer-events="none"> <!-- Top line --> <path d="M 20 30 L 80 30" class="line line-1"> <animate attributeName="d" from="M 20 30 L 80 30" to="M 20 20 L 80 80" dur="0.3s" begin="iconOn.click" fill="freeze" /> <animate attributeName="d" from="M 20 20 L 80 80" to="M 20 30 L 80 30" dur="0.3s" begin="iconOff.click" fill="freeze" /> </path> <!-- Middle line --> <path d="M 20 50 L 80 50" class="line line-2"> <animate attributeName="opacity" from="1" to="0" dur="0.3s" begin="iconOn.click" fill="freeze" /> <animate attributeName="opacity" from="0" to="1" dur="0.3s" begin="iconOff.click" fill="freeze" /> </path> <!-- Bottom line --> <path d="M 20 70 L 80 70" class="line line-3"> <animate attributeName="d" from="M 20 70 L 80 70" to="M 20 80 L 80 20" dur="0.3s" begin="iconOn.click" fill="freeze" /> <animate attributeName="d" from="M 20 80 L 80 20" to="M 20 70 L 80 70" dur="0.3s" begin="iconOff.click" fill="freeze" /> </path> </g> </svg>