CSS Button Styles
Here are four button styles that you can copy to your site. The same CSS works for <button> and for links with the class btn.
HTML
<button class="btn btn-primary">Primary</button>
<button class="btn btn-outline">Outline</button>
<button class="btn btn-pill">Pill</button>
<button class="btn btn-primary" disabled>Disabled</button>
CSS
.btn {
padding: 10px 22px;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s, color 0.2s;
}
.btn-primary {
background: #0073aa;
color: #fff;
border: 2px solid #0073aa;
}
.btn-primary:hover { background: #005177; border-color: #005177; }
.btn-outline {
background: transparent;
color: #0073aa;
border: 2px solid #0073aa;
}
.btn-outline:hover { background: #0073aa; color: #fff; }
.btn-pill { border-radius: 999px; background: #43a047; color: #fff; border: 2px solid #43a047; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid orange; outline-offset: 2px; }
Output in the browser (hover colours do not show in this box):
Output in the browser
Note:
Keep the :focus-visible style, so keyboard users can see which button is selected. See CSS Links for link buttons.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Borders |
| Rounded Corners in CSS |
| CSS Height and Width |
| CSS Padding |
| CSS Margins |
| CSS Box Model |
| CSS Outline |
| Exercises & Assignments |
|---|
| Write CSS to create a box with border, padding and rounded corners |
| Write CSS to create a circle and a pill-shaped button |
| Write CSS to style a login form |
| Interview Questions & Answers |
|---|
| What is the CSS box model? |
| What is the difference between margin and padding in CSS? |
| What is box-sizing: border-box in CSS? |