About this snippet

Navigate between sections with style. A background pill slides smoothly to the active tab using pure CSS and radio buttons, which gives your interface a native application feel without JavaScript.

Size
1.6 KB
Uses
HTML, CSS
Loads
Nothing external
Views
509
<div class="slide-tabs">
  <input type="radio" id="radio-1" name="tabs" checked>
  <label class="tab" for="radio-1">Code</label>
  <input type="radio" id="radio-2" name="tabs">
  <label class="tab" for="radio-2">Issues</label>
  <input type="radio" id="radio-3" name="tabs">
  <label class="tab" for="radio-3">Pull Requests</label>
  <span class="glider"></span>
</div>
.slide-tabs {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  display: flex;
  position: relative;
  background-color: #f3f4f6;
  box-shadow: 0 0 1px 0 rgba(24, 94, 224, 0.15), 0 6px 12px 0 rgba(24, 94, 224, 0.15);
  padding: 5px;
  border-radius: 99px;
  max-width: 400px;
  margin: 0 auto;
}
input[type="radio"] {
  display: none;
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  width: 100%;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 99px;
  cursor: pointer;
  transition: color 0.15s ease-in;
  z-index: 2;
  color: #4b5563;
}
.glider {
  position: absolute;
  display: flex;
  height: 40px;
  width: 32%; /* Approx 1/3 minus padding */
  background-color: #fff;
  z-index: 1;
  border-radius: 99px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
input[id="radio-1"]:checked ~ .glider {
  transform: translateX(0%);
}
input[id="radio-2"]:checked ~ .glider {
  transform: translateX(100%);
}
input[id="radio-3"]:checked ~ .glider {
  transform: translateX(200%);
}
input:checked + label {
  color: #1f2937;
  font-weight: 600;
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save