Trace a button’s edge when it becomes available
Jhey’s CSS demo sends a narrow highlight around a button. Try how much of the edge to light and when to draw attention to it.
Jhey · CSS · Source postAuthor’s demo
Flash the button's border once
An independent web example inspired by the original reference.
Type a message, clear it, and type again. With reduced motion enabled in your device settings, the edge stays still.
Implementation steps
- Trigger the highlight when the message field goes from empty to ready to send.
- Split the button into inner and outer layers. Rotating the outer gradient lights only the border without moving the text.
- Animate only when switching from disabled to enabled. With reduced motion, convey the state through a static border and color change.
Acceptance check
It doesn't flash repeatedly while typing, and empty fields can't be submitted. Enabled and disabled states stay clear even with reduced motion.
View sample code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flash the button's border once</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 16px;
background: #23232a;
color: #f4f0ea;
font: 16px/1.6 system-ui, sans-serif;
}
label, output, strong, audio, progress { display: block; margin: 6px 0; }
input, select, button { max-width: 100%; font: inherit; }
input, select { padding: 4px 7px; }
button {
margin: 4px 0;
padding: 5px 12px;
cursor: pointer;
border: 1px solid #b5a399;
border-radius: 6px;
}
:focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
audio { width: 100%; }
[hidden] { display: none !important; }
#send {
position: relative;
isolation: isolate;
overflow: hidden;
background: #31313a;
border: 0;
border-radius: 10px;
color: white;
padding: 10px 24px;
}
#send::before, #send::after {
content: "";
position: absolute;
z-index: -1;
pointer-events: none;
}
#send::before {
inset: -100%;
background: conic-gradient(#e5aa78, #795436 65%, white 80%, #d89659);
}
#send::after {
inset: 2px;
border-radius: 8px;
background: #514133;
}
#send:disabled { opacity: .45; }
@media (prefers-reduced-motion: no-preference) {
#send.ready::before { animation: sweep .7s ease-out; }
}
@keyframes sweep { to { transform: rotate(1turn); } }
</style>
</head>
<body>
<label>Message <input id="message"></label>
<button id="send" disabled>Send</button>
<output id="result"></output>
<script>
const input = document.querySelector('#message');
const send = document.querySelector('#send');
function update() {
const ready = input.value.trim().length > 0;
send.disabled = !ready;
send.classList.toggle('ready', ready);
}
input.addEventListener('input', update);
send.onclick = () => {
document.querySelector('#result').textContent = 'Message sent (demo)';
input.value = '';
update();
};
</script>
</body>
</html>Save as index.html and open in a browser to run it locally.