Ghost Button Fill Slide
An outlined button whose fill slides in from the left, bottom or corner on hover and keyboard focus.
AI prompt
Clean UI mockup showing the same outlined button in three states in a row: resting with a dark border and dark text on white, half filled with a dark colour sweeping from left to right with the text turning white where covered, and fully filled dark with white text, the label Learn more with a small arrow, light theme, flat modern style. Negative: gradients, heavy shadows, clutter, text errors. Reduced motion: static design.About this pattern
Definition
A ghost button is an outlined secondary action. A sliding fill on hover adds a clear, tactile response without moving the layout. It is built by animating the size or position of a background gradient, so the button keeps its shape while colour sweeps through it.
Purpose & UX principles
- Paint a solid colour as a background image sized zero by default and grow it on hover and focus-visible.
- Direction is set by background-position and which axis grows.
- Switch the text colour at the same moment so contrast stays high throughout.
- Keep the transition between 200 and 300 ms.
Interaction states
- Direction buttons and three live buttons to hover, focus or press.
Motion specification
- The fill slides in 250ms.
- Reduced motion: the colour changes instantly.
Responsive behaviour
- Fill colour and text colour must both meet contrast in every state.
- Do not animate on touch hover because it can stick after a tap; use active instead.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Direction"><button data-p="0" aria-pressed="true">From left</button><button data-p="1" aria-pressed="false">From bottom</button><button data-p="2" aria-pressed="false">From corner</button></div><div class="row" id="row"><button class="gb" type="button">Learn more →</button><button class="gb" type="button">View plans</button><button class="gb" type="button">Contact</button></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.row{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;padding:22px 8px;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.gb{padding:10px 18px;border:1.5px solid #171717;border-radius:10px;font-size:13px;font-weight:600;color:#171717;background:linear-gradient(#171717,#171717) var(--bp,0 50%)/var(--bs,0% 100%) no-repeat;transition:background-size .25s,color .25s}.gb:hover,.gb:focus-visible{--bs:100% 100%;color:#fff;background-size:var(--bs)}.row[data-d="1"] .gb{--bp:50% 100%;--bs:100% 0%}.row[data-d="1"] .gb:hover,.row[data-d="1"] .gb:focus-visible{--bs:100% 100%}.row[data-d="2"] .gb{--bp:0 0;--bs:0% 0%}.row[data-d="2"] .gb:hover,.row[data-d="2"] .gb:focus-visible{--bs:100% 100%}@media (prefers-reduced-motion:reduce){.gb{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const row=document.getElementById('row'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){row.dataset.d=p;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ghost Button Fill Slide — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.row{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;padding:22px 8px;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.gb{padding:10px 18px;border:1.5px solid #171717;border-radius:10px;font-size:13px;font-weight:600;color:#171717;background:linear-gradient(#171717,#171717) var(--bp,0 50%)/var(--bs,0% 100%) no-repeat;transition:background-size .25s,color .25s}.gb:hover,.gb:focus-visible{--bs:100% 100%;color:#fff;background-size:var(--bs)}.row[data-d="1"] .gb{--bp:50% 100%;--bs:100% 0%}.row[data-d="1"] .gb:hover,.row[data-d="1"] .gb:focus-visible{--bs:100% 100%}.row[data-d="2"] .gb{--bp:0 0;--bs:0% 0%}.row[data-d="2"] .gb:hover,.row[data-d="2"] .gb:focus-visible{--bs:100% 100%}@media (prefers-reduced-motion:reduce){.gb{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Direction"><button data-p="0" aria-pressed="true">From left</button><button data-p="1" aria-pressed="false">From bottom</button><button data-p="2" aria-pressed="false">From corner</button></div><div class="row" id="row"><button class="gb" type="button">Learn more →</button><button class="gb" type="button">View plans</button><button class="gb" type="button">Contact</button></div></div>
</div>
<script>
const row=document.getElementById('row'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){row.dataset.d=p;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));up();
</script>
</body></html>