Skip to content

Seasonal opening hours in HTML and CSS

Two tabs to show different opening hours by season, in a compact card.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Horaires par saison</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div class="stabs" data-tabs>
        <h2>Horaires du fournil</h2>
style.css
:root {
  --st-card: #ffffff;
  --st-text: #2b1a0e;
  --st-muted: #6b4a33;
  --st-line: #ead9c6;
  --st-track: #f5e6d3;
  --st-active: #8a4b1f;
  --st-active-text: #ffffff;
  --st-ring: #8a4b1f;
  --demo-bg: #fbf6f0;
  --demo-text: #2b1a0e;
}
tabs.js
document.querySelectorAll("[data-tabs]").forEach((root) => {
  const list = root.querySelector('[role="tablist"]');
  const tabs = [...list.querySelectorAll('[role="tab"]')];
  const panels = tabs.map((tab) => document.getElementById(tab.getAttribute("aria-controls")));
  const vertical = list.getAttribute("aria-orientation") === "vertical";

  function select(index, focus) {
    tabs.forEach((tab, position) => {
      const selected = position === index;
      tab.setAttribute("aria-selected", String(selected));
      tab.tabIndex = selected ? 0 : -1;
      panels[position].hidden = !selected;

Free component: copy it freely, including for commercial projects.

Tabs components in HTML and CSS
  • Accessible tabs on large screens that turn into an accordion on phones, with the right ARIA roles in each mode.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Indicative prices sorted by trade in tabs, with the unit of each service, a VAT-inclusive / excl. switch and a free-quote notice.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Understated tabs with an underlined active tab, to organize the information on a product page.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A dark code block with one tab per package manager, for technical documentation.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component