Hairline CSS button
Thin white outline on dark that inverts on hover. Hover, click and tab to it to see every state.
CSS
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: .5em;
padding: 14px 28px;
font-family: 'Inter', sans-serif;
font-size: 16px;
font-weight: 600;
line-height: 1.2;
color: #ffffff;
background: rgba(255, 255, 255, 0);
border: 1px solid rgba(255, 255, 255, .34999999999999997779553950749686919152736663818359375);
border-radius: 8px;
cursor: pointer;
text-decoration: none;
white-space: nowrap;
-webkit-tap-highlight-color: transparent;
transition: transform 200ms cubic-bezier(.2,.8,.2,1), box-shadow 200ms cubic-bezier(.2,.8,.2,1), filter 200ms cubic-bezier(.2,.8,.2,1), background 200ms cubic-bezier(.2,.8,.2,1), color 200ms cubic-bezier(.2,.8,.2,1);
}
.btn:hover {
background: #ffffff;
color: #09090b;
}
.btn:active {
transform: translateY(1px) scale(0.979999999999999982236431605997495353221893310546875);
transition-duration: 100ms;
}
.btn:focus-visible {
outline: 3px solid #ffffff;
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.btn {
transition: none;
animation: none;
}
}
HTML
<button class="btn" type="button">
View work
</button>
How this button is built
- Background: transparent, so the button takes the colour of whatever is behind it.
- Type: Inter, weight 600, 16px, in #ffffff.
- Shape: 8px rounded corners with 14px × 28px padding, plus a 1px solid border.
- Interaction: on hover it switches to #ffffff with #09090b text, and it squishes slightly when clicked, with 200ms transitions.
- Accessibility: a visible
:focus-visiblering for keyboard users, and all motion turns off underprefers-reduced-motion.
How to use it
- Copy the CSS into your stylesheet. The
@importline loads the Inter font from Google Fonts. Move it to the top of your file, or drop it if you already load the font. - Paste the HTML where you want the button. It works on
<button>,<a>and<input type="submit">. - Change the label, or rename the
.btnclass if it clashes with your framework. Want a different colour or size? Open it in the editor, change it visually, and copy the new code.