On this page11 sections
  1. Learning Objectives
  2. 1. A Good Base Button
  3. 2. Colours, Sizes and Shapes
  4. 3. Icon and Loading Buttons
  5. 4. Button Groups
  6. 5. Pagination
  7. 6. Breadcrumbs
  8. Common Beginner Mistakes
  9. Practice Questions
  10. Practice Answers
  11. Key Takeaways

Lecture 044: Buttons & Pagination

Category7: Advanced Styling
Lecture044 of 057
Estimated video length12 min
TargetCSS3 · any modern browser
LevelIntermediate

Buttons are the most-clicked things on a page, so they deserve care: clear colours, sizes, hover and press feedback, disabled states and groups. Pagination (the 1 2 3 Next bar) is a row of small buttons, so it uses the same skills.


Learning Objectives

  • Style buttons with colour, size, radius and shadow
  • Add hover, active, focus and disabled states
  • Build outline, pill, icon and loading buttons
  • Group buttons, and build pagination and breadcrumbs

1. A Good Base Button

Example

html
<style>
  .btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; border: 2px solid transparent; border-radius: 8px;
    font: 600 15px system-ui, sans-serif; cursor: pointer;
    background: #1971c2; color: white;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  }
  .btn:hover { background: #1864ab; }
  .btn:active { transform: translateY(1px); }
  .btn:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }
  .btn:disabled { opacity: 0.5; cursor: not-allowed; }
</style>

<button class="btn">Save</button>
<button class="btn" disabled>Disabled</button>

2. Colours, Sizes and Shapes

Example

html
<style>
  .btn { padding: 10px 18px; border: 2px solid transparent; border-radius: 8px; font: 600 15px system-ui; cursor: pointer; margin: 3px; color: white; }
  .green { background: #2f9e44; } .red { background: #e03131; } .grey { background: #868e96; }
  .outline { background: white; color: #1971c2; border-color: #1971c2; }
  .outline:hover { background: #1971c2; color: white; }
  .pill { border-radius: 999px; background: #7048e8; }
  .small { padding: 5px 10px; font-size: 13px; background: #1971c2; }
  .large { padding: 14px 26px; font-size: 18px; background: #1971c2; }
  .block { display: block; width: 100%; background: #212529; }
  .shadow { background: #f76707; box-shadow: 0 4px 0 #c2410c; }
  .shadow:active { box-shadow: 0 1px 0 #c2410c; transform: translateY(3px); }
</style>

<button class="btn green">Success</button>
<button class="btn red">Delete</button>
<button class="btn grey">Cancel</button>
<button class="btn outline">Outline</button>
<button class="btn pill">Pill</button>
<br>
<button class="btn small">Small</button>
<button class="btn large">Large</button>
<button class="btn shadow">Press me</button>
<button class="btn block">Full width</button>

3. Icon and Loading Buttons

Example

html
<style>
  .btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 0; border-radius: 8px; background: #1971c2; color: white; font: 600 15px system-ui; }
  .spinner { width: 14px; height: 14px; border: 2px solid rgb(255 255 255 / 0.4); border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .icon-only { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; }
</style>

<button class="btn">⬇ Download</button>
<button class="btn" disabled><span class="spinner"></span> Saving…</button>
<button class="btn icon-only" aria-label="Add">+</button>

4. Button Groups

Example

html
<style>
  .group { display: inline-flex; }
  .group button { padding: 8px 14px; border: 1px solid #1971c2; background: white; color: #1971c2; font: 14px system-ui; cursor: pointer; }
  .group button + button { border-left: 0; }
  .group button:first-child { border-radius: 8px 0 0 8px; }
  .group button:last-child { border-radius: 0 8px 8px 0; }
  .group button.active, .group button:hover { background: #1971c2; color: white; }
</style>

<div class="group" role="group" aria-label="View">
  <button class="active">Day</button><button>Week</button><button>Month</button>
</div>

5. Pagination

Example

html
<style>
  .pagination { display: flex; gap: 4px; list-style: none; padding: 0; font: 14px system-ui; }
  .pagination a { display: block; min-width: 36px; padding: 8px 10px; text-align: center; border-radius: 6px; color: #343a40; text-decoration: none; border: 1px solid #dee2e6; }
  .pagination a:hover { background: #f1f3f5; }
  .pagination a[aria-current="page"] { background: #1971c2; border-color: #1971c2; color: white; }
  .pagination .disabled a { color: #adb5bd; pointer-events: none; }
</style>

<nav aria-label="Pages">
  <ul class="pagination">
    <li class="disabled"><a href="#">‹ Prev</a></li>
    <li><a href="#" aria-current="page">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">…</a></li>
    <li><a href="#">12</a></li>
    <li><a href="#">Next ›</a></li>
  </ul>
</nav>

aria-current="page" both styles the current page and tells screen readers which page you're on.


6. Breadcrumbs

Example

html
<style>
  .crumbs { display: flex; flex-wrap: wrap; list-style: none; padding: 0; font: 14px system-ui; }
  .crumbs li + li::before { content: "/"; margin: 0 8px; color: #adb5bd; }
  .crumbs a { color: #1971c2; text-decoration: none; }
</style>

<nav aria-label="Breadcrumb">
  <ol class="crumbs"><li><a href="#">Home</a></li><li><a href="#">Courses</a></li><li>CSS</li></ol>
</nav>

Common Beginner Mistakes

1. No hover or focus state. Visitors can't tell the button is interactive.

2. Low-contrast colours. White text on yellow, for example, is hard to read.

3. Tiny tap targets. Aim for at least 40×40px on touch screens.

4. Disabled buttons that look active. Lower the opacity and show cursor: not-allowed.


Practice Questions

  1. Write an outline button that fills with colour on hover.
  2. How do you make a pill-shaped button?
  3. How do you style a disabled button?
  4. In a button group, how do you round only the outer corners?
  5. Which attribute marks the current page in pagination?

Practice Answers

  1. .btn { background: white; color: blue; border: 2px solid blue; } .btn:hover { background: blue; color: white; }
  2. border-radius: 999px;
  3. .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  4. Round the left corners of :first-child and the right corners of :last-child.
  5. aria-current="page"

Key Takeaways

  • A good button has padding, contrast, a radius and hover, active, focus and disabled states.
  • Variants: outline, pill, sizes, full width, icon and loading.
  • Groups and pagination are rows of buttons; style the current one with aria-current.