How to Design a Timeline Section on a Website With HTML and CSS (Vertical and Horizontal)

In short: a CSS timeline is an ordered list of events with three visual pieces added on top: a line, a marker for each event, and a content card. You draw the line and the markers with pseudo-elements, so the HTML stays a clean <ol>. Build the single-column vertical version first, because it works on every phone. Then add an alternating two-column layout with CSS Grid, or a horizontal strip, from a desktop breakpoint.

Timelines show up on agency “About” pages, product changelogs, onboarding steps and résumés. In our view, a timeline snippet is only worth using if it survives a card with more text than the demo, and a narrow screen. This tutorial builds one component that survives real content. It covers the markup, the vertical layout for mobile, the alternating and horizontal variants for desktop, animation that respects user settings, and the accessibility checks that most examples skip.

How a CSS timeline works

Every timeline you’ve seen is the same mechanism dressed differently. The list holds the events in chronological order.

The list’s ::before pseudo-element draws one continuous line along an axis: the vertical axis for a stacked layout, or a horizontal one for a strip. Each list item’s own ::before draws a dot that sits on that line. The card then takes the remaining space beside the dot.

Pseudo-elements are boxes that CSS generates without any extra HTML, using content: "". That’s why the line and the dots never appear in the markup, and why a screen reader ignores them.

Positioning works in two layers: the list gets position: relative, and the line and dots get position: absolute inside it. Once you see it this way, every timeline design you find online becomes a set of variations on spacing, color and which side the card sits on.

To follow along, you need two files: index.html for the markup and style.css for the styles, linked with a <link rel="stylesheet" href="style.css"> tag in the <head>. You can also paste the source code below into a new CodePen: HTML in the HTML panel, CSS in the CSS panel, and the preview updates automatically as you type.

website timeline design

Which timeline layout fits your content?

The layout depends on how much text each event carries and how many events you have. A short process with four steps reads well horizontally. A company history with paragraphs per year does not.

Use case Layout to use Avoid
Company or agency history, 5 to 15 milestones with short paragraphs Vertical on mobile, alternating two columns on desktop A horizontal slider that hides most years off screen
Service process, 3 to 6 steps with one sentence each Horizontal row on desktop, vertical on mobile Alternating cards, which waste space for one-liners
Changelog or release notes that keep growing Single-column vertical with sticky dates Zigzag layouts, which get hard to scan once the list grows long
Résumé or portfolio page Two columns: fixed-width dates on the left, details on the right Icon-heavy designs where the dates become decoration
Event schedule for one day Vertical list with times in <time> elements Carousels that need a click per time slot

For an agency site, we’d start with the vertical layout almost every time. It holds any amount of text, and the desktop upgrade is a few lines of CSS. Horizontal timelines look impressive in a design review, but to our mind they need the most care on a phone, since the strip has to scroll or reflow.

The markup: an ordered list, real dates and headings

A timeline is a sequence, so the natural element is an ordered list. You could argue that <ul> is enough when you don’t display the numbers.

We prefer <ol>, because order is the meaning of the component, and the element states that whether or not the numbers are visible. The sighted user gets the order from the line; the screen reader user gets it from the list.

<ol class="timeline" role="list">
  <li class="timeline__item">
    <time class="timeline__date" datetime="2014-03">March 2014</time>
    <div class="timeline__card">
      <h3>Studio founded</h3>
      <p>Two designers, one shared office and a first client in retail.</p>
    </div>
  </li>
  <li class="timeline__item">
    <time class="timeline__date" datetime="2018">2018</time>
    <div class="timeline__card">
      <h3>First e-commerce rebuild</h3>
      <p>The team grows to six people.</p>
    </div>
  </li>
</ol>

Three details in this snippet matter more than they look:

  • The <time datetime> element, introduced with HTML5 (the 2014 revision of HTML that added many semantic elements), gives each date a machine-readable value. The HTML Living Standard accepts years, year-months and full dates, so “2014-03” is valid.
  • A heading for each event title lets screen reader users jump from event to event. Pick the level that fits your page outline, usually <h3> under the section’s <h2>.
  • role="list" looks redundant, but Safari with VoiceOver drops list semantics when you set list-style: none. Adding the role puts them back.

Some snippets store the date in a data attribute, such as <li data-date="2025">, and print it with content: attr(data-date). It keeps the markup short, but assistive technology handles generated content unreliably, and visitors can’t select or copy it. Keep dates as real text. Also skip the icon fonts and image icons that many older demos use for markers: if an icon carries no information, it’s decoration and belongs in CSS. Building a Horizontal Timeline With CSS and JavaScript covers this in more depth.

website timeline design

Build the vertical timeline first (mobile)

The single-column version is the base for every other layout. Custom properties (CSS variables) hold the sizes, so the line and the dots stay aligned when you change one value.

.timeline {
  --line: 2px;
  --dot: 14px;
  --gap: 1.5rem;
  --accent: #1f6feb;
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

/* The line */
.timeline::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: calc(var(--dot) / 2 - var(--line) / 2);
  width: var(--line);
  background: #c9d3dd;
}

.timeline__item {
  position: relative;
  padding-inline-start: calc(var(--dot) + var(--gap));
  padding-block-end: 2rem;
}

/* The marker */
.timeline__item::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0.3em;
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px #fff;
}

.timeline__date {
  display: block;
  font-weight: 600;
}

The box-shadow ring around each dot hides the line behind it, so the marker looks punched out of the axis. Match the ring color to your page background. For a softer timeline UI (user interface), swap the solid line for a linear-gradient() that fades to transparent at the bottom, which also signals that the story continues.

If you write Sass, you could store these sizes in Sass variables instead. Custom properties have one advantage here: they can change inside a media query or on a single item, at runtime, without recompiling anything.

Notice the properties: inset-inline-start instead of left, padding-inline-start instead of padding-left. These are logical properties.

They follow the writing direction, so the same CSS puts the line on the right for Arabic or Hebrew pages without a single override. If your site will only ever run in English, plain left works too. Logical properties just remove a future bug for free.

The marker sits at a fixed offset from the top of each item, not at a calculated position. That’s deliberate. Timelines built with absolute positioning for the whole item need a top value per event, and they break as soon as one card grows. Here, each item stays in normal flow, so a long paragraph simply pushes the next event down.

Alternating two-column layout with CSS Grid

From a tablet width, the classic look puts the line in the center and alternates cards left and right. CSS Grid handles this without floats or fixed widths. Each item becomes a three-column grid: card, marker, date.

@media (min-width: 48rem) {
  .timeline--alternate::before {
    inset-inline-start: 50%;
    margin-inline-start: calc(var(--line) / -2);
  }

  .timeline--alternate .timeline__item {
    display: grid;
    grid-template-columns: 1fr var(--dot) 1fr;
    column-gap: var(--gap);
    padding-inline-start: 0;
  }

  .timeline--alternate .timeline__item::before {
    position: static;
    grid-column: 2;
    grid-row: 1;
    margin-block-start: 0.3em;
  }

  .timeline--alternate .timeline__item:nth-child(odd) .timeline__card,
  .timeline--alternate .timeline__item:nth-child(even) .timeline__date {
    grid-column: 1;
    grid-row: 1;
    text-align: end;
  }

  .timeline--alternate .timeline__item:nth-child(odd) .timeline__date,
  .timeline--alternate .timeline__item:nth-child(even) .timeline__card {
    grid-column: 3;
    grid-row: 1;
  }
}

Two things make this work. First, a pseudo-element is a grid item like any other, so the dot drops into the middle column with grid-column: 2. Second, nth-child(odd) and nth-child(even) swap the card and the date, which creates the zigzag. The HTML order never changes, so keyboard and screen reader users still read date, then event, in sequence.

A note on complexity: you’ll find timeline components with a dozen calc() expressions for positioning. You rarely need them.

One line, one dot size and a gap cover almost every design. If you want to number or stagger events automatically, CSS counters already work everywhere. The newer sibling-index() function from CSS Values and Units Level 5 is meant for exactly that, but check its browser support before you rely on it.

website timeline design

Horizontal timeline variant for desktop

A horizontal timeline suits short sequences, such as a four-step process on a service page. The line runs along the top of the items, and the strip scrolls sideways when there are more events than fit.

<div class="timeline-scroller" role="region" aria-label="Our process" tabindex="0">
  <ol class="timeline timeline--horizontal" role="list"> … </ol>
</div>
@media (min-width: 64rem) {
  .timeline-scroller {
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .timeline--horizontal {
    display: flex;
    width: max-content;
  }

  .timeline--horizontal::before {
    display: none;
  }

  .timeline--horizontal .timeline__item {
    flex: 0 0 16rem;
    scroll-snap-align: start;
    padding: calc(var(--dot) + var(--gap)) var(--gap) 0 0;
    border-block-start: var(--line) solid #c9d3dd;
  }

  .timeline--horizontal .timeline__item::before {
    inset-block-start: calc(var(--dot) / -2 - var(--line) / 2);
  }
}

Here the line comes from each item’s top border instead of a single pseudo-element. Borders travel with every item, so the line always matches the number of events, even after an editor adds one. Scroll snapping (scroll-snap-type on the container, scroll-snap-align on the items) makes the strip stop cleanly on an event instead of halfway through a card.

The wrapper carries tabindex="0", a role="region" and a label. Some browsers don’t let keyboard users focus a scroll container on its own. The tabindex makes the strip focusable everywhere, so arrow keys can scroll it, and the role and label tell screen reader users what they’ve landed on.

Below 64rem the media query doesn’t apply, so the same list falls back to the vertical layout. That fallback matters for accessibility. The Web Content Accessibility Guidelines (WCAG) 2.2 cover it in success criterion 1.4.10 (Reflow). Content must stay usable at a width equivalent to 320 CSS pixels, without scrolling in two directions. A simple timeline using CSS flexbox tackles the same question from another angle.

If the design calls for a snaking path that zigzags across rows, treat it as a desktop-only extra. Stacked boxes with borders on alternate sides, selected with nth-of-type, can draw that path, but it doesn’t scale down. Switch to the plain vertical line at your breakpoint instead of trying to shrink the snake.

Animating events without hiding content

Scroll-triggered reveals are popular on timelines: each event fades and slides in as it enters the viewport. Animate only these two CSS properties: transform (or translate) and opacity. The same goes for a hover transition on the cards. Browsers can run these two on the compositor, so the page doesn’t recalculate its layout on every frame.

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .timeline__card {
      animation: reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 30%;
    }
  }
}

@keyframes reveal {
  from { opacity: 0; translate: 0 1rem; }
  to   { opacity: 1; translate: 0 0; }
}

This uses scroll-driven animations, which tie the animation to the element’s position in the viewport with no JavaScript. Older browsers don’t know these properties, so the @supports test matters. Where they’re missing, the cards simply appear, fully visible. The prefers-reduced-motion media query skips the effect for visitors who asked their system for less motion, which matches the intent of WCAG 2.3.3 (Animation from Interactions).

For broader support, the usual JavaScript route is an IntersectionObserver that adds a class when a card enters the viewport. Set the hidden state from JavaScript, not in your stylesheet. Otherwise a script error leaves the whole history invisible.

website timeline design

Timeline examples worth studying

Studying a few well-known demos teaches more than copying one. These public examples each show a technique worth reusing:

  • Timeline with Sticky Dates (FreeFrontend collection): pure CSS, with position: sticky pinning the year while its events scroll past. Ideal for long changelogs.
  • UL Timeline Cards (same collection, built on an unordered <ul> list): CSS Grid draws a central divider with grid-template-columns, while ::before and ::after handle the date tabs and anchor circles. Close to the method in this article.
  • Wheel Timeline: a radial carousel in pure CSS, positioned with calc() and driven by the radio button hack and :has(). A good lesson in CSS-only state, less so in readability.
  • Codyhouse horizontal timeline: a minimal line with clickable points that slide the content sideways. It needs JavaScript, and it shows how a horizontal timeline can stay light.
  • Envato Tuts+ horizontal timeline: clean, basic cards along a horizontal line, with red dots marking each interval. A clear starting point for a process strip.
  • Responsive timeline slider: built on the Swiper library, with years listed at the side and buttons to move between them. Useful when each year needs a full-screen image.

Look at how each one handles a narrow screen before you borrow anything. Many older demos rely on floats and fixed percentages, so test their cards at phone width before reusing them.

Pure CSS, a little JavaScript, or a library?

Approach Time to build Skill needed Good for Watch out for
Pure HTML and CSS Shortest CSS Flexbox, Grid, pseudo-elements History pages, processes, résumés Radio-button hacks for interactivity, which in our view are hard to make accessible
CSS plus a small script Longer: you also write and test the script Basic JavaScript, IntersectionObserver Reveals, “current year” highlighting, filters Content hidden until the script runs
Slider or timeline library Fast to start, slower to customize Reading the library’s docs Image-heavy, interactive timelines Extra weight, markup you don’t control, focus handling

For a CMS-driven site, the pure CSS version also has a practical advantage: editors can add an event by adding a list item. Nobody has to recalculate anything.

website timeline design

Six common timeline pitfalls

  • The line runs past the last event. Cause: the line spans 100% of the list, including the last item’s bottom padding. Fix: remove padding-block-end from .timeline__item:last-child, or end the line with inset-block-end set to that padding.
  • Markers drift away from the line. Cause: the dot and the line use unrelated values. Fix: compute both from the same --dot and --line variables, as above.
  • Cards overlap on tablets. Cause: floats (float: left and float: right) or absolute positioning with fixed widths. Fix: keep items in normal flow and let Grid or Flexbox place them.
  • Markers are cut in half. Cause: overflow: hidden on the list items, a leftover in many older snippets, clips anything that sticks out of the item box. Fix: remove it, or move the clipping to the card only.
  • The horizontal strip traps keyboard users. Cause: a scroll container that can’t receive focus. Fix: tabindex="0", a role and a label on the wrapper. If you add previous and next buttons for navigation, scroll the wrapper with scrollBy({ left: 256, behavior: "smooth" }) rather than moving items with JavaScript.
  • Markers vanish against the background. Cause: pale gray dots chosen for looks. Fix: when the marker conveys state, such as “current step”, give it at least a 3:1 contrast ratio with its surroundings, the WCAG 1.4.11 (Non-text Contrast) threshold. Body text in cards needs 4.5:1 under WCAG 1.4.3.

Testing checklist for your CSS timeline

  1. Resize the browser to 320 pixels wide: one column, no sideways scrolling, no overlapping cards.
  2. Add a card with three times the usual text: the next event moves down and the marker stays on the line.
  3. Tab through the page: every link inside the timeline is reachable, and a horizontal strip can be scrolled with the arrow keys.
  4. Run a screen reader over it: it announces a list with the right number of items, and the headings appear in the headings list.
  5. Turn on “reduce motion” in your operating system: no event slides or fades.
  6. Disable JavaScript: all events stay visible.
  7. Switch the page to dir="rtl" if you serve such languages: the line moves to the other side.
  8. Check contrast for text, markers and the line against the background.

FAQ

Can I build a timeline with Flexbox only, without Grid?

Yes. A vertical timeline needs neither, and the alternating layout works with Flexbox and flex-direction: row-reverse on even items. Grid is simpler when you want the dot centered in its own column, because you don’t have to compensate for card widths.

How do I make a timeline in WordPress without code?

Some page builders and block plugins include a timeline block, so check what yours offers first. If you’d rather keep your theme light, add the CSS from this article to your theme or the Additional CSS panel. Then build the list in a Custom HTML block or a List block with a class.

How do I highlight the current event?

Add a class such as is-current to that list item and give its marker a different color or a larger size. Also add aria-current="step" so screen readers announce it, since color alone doesn’t carry meaning for every visitor. mozilla.org published something useful on the subject.

Should timeline dates use container queries instead of media queries?

If the same component appears in a wide content area and a narrow sidebar, yes. Container queries switch the layout based on the space the timeline actually has, not the screen width. Declare container-type: inline-size on the parent, then replace @media with @container.

The fastest way to a timeline that holds up is to write the ordered list first, with real dates and headings. Style the vertical version next, and only then add the desktop layout you need.

Whether you’re a web designer polishing a client’s site or a developer cleaning up a modern web stack, the method stays the same. Take one page of your site with dated content, such as an “About” page or a process section, and rebuild it with this component today.

Want more practical front-end tutorials like this one? Browse our other web design and development guides.

Recent Posts

No Posts Found!

Categories

Tags

    Subscribe

    You have been successfully Subscribed! Ops! Something went wrong, please try again.

    About Us

    Express Jam Studio was founded in 2004 by John Smith. John had previously worked for a courier company, but he saw an opportunity to start his own business in the web design and development industry.

    Contact Info

    Copyright © 2022 Express Jam Studio. All Rights Reserved.