---
category: Display
created: '2021-04-18'
description: Create a zigzag timeline
keywords: css timeline, css zigzag timeline
thumbnail: /assets/css-layout/thumbnails/zigzag-timeline.png
title: Zigzag timeline
---

## HTML

```html index.html
<div class="zigzag-timeline__item">
    <!-- Milestone -->
    <div className="zigzag-timeline__milestone">...</div>

    <!-- Content -->
    ...
</div>

<!-- Repeat other items -->
...
```

## CSS

```css styles.css
.zigzag-timeline__item {
    /* Used to position the milestone */
    position: relative;

    /* Border */
    border-bottom: 1px solid #9ca3af;

    /* Take full width */
    width: 100%;
}

.zigzag-timeline__milestone {
    /* Absolute position */
    position: absolute;
    top: 50%;

    /* Circle it */
    border-radius: 50%;
    height: 1rem;
    width: 1rem;

    /* Misc */
    background: #9ca3af;
}

/* Styles for even items */
.zigzag-timeline__item:nth-child(2n) {
    border-left: 1px solid #9ca3af;
}
.zigzag-timeline__item:nth-child(2n) .zigzag-timeline__milestone {
    left: 0;
    transform: translate(-50%, -50%);
}

/* Styles for odd items */
.zigzag-timeline__item:nth-child(2n + 1) {
    border-right: 1px solid #9ca3af;
}
.zigzag-timeline__item:nth-child(2n + 1) .zigzag-timeline__milestone {
    right: 0;
    transform: translate(50%, -50%);
}
```

<Playground>
```css placeholders.css hidden
.lines {
    padding: 0.25rem 0;
    width: 100%;
    align-items: center;
    display: flex;
    justify-content: center;
    flex-direction: column;
}
.line {
    background: #d1d5db;
    height: 1px;
    margin-bottom: 0.25rem;
}
.line.line--20 {
    width: 20%;
}
.line.line--40 {
    width: 40%;
}
.line.line--60 {
    width: 60%;
}
.line.line--80 {
    width: 80%;
}
.line.line--100 {
    width: 100%;
}
```

```css styles.css hidden
body {
    display: flex;
    align-items: center;
    justify-content: center;
}

.zigzag-timeline {
    width: 16rem;
}

.zigzag-timeline__item {
    /* Used to position the milestone */
    position: relative;

    /* Border */
    border-bottom: 1px solid #9ca3af;

    /* Take full width */
    width: 100%;
}

.zigzag-timeline__milestone {
    /* Absolute position */
    position: absolute;
    top: 50%;

    /* Circle it */
    border-radius: 50%;
    height: 1rem;
    width: 1rem;

    /* Misc */
    background: #9ca3af;
}

/* Styles for even items */
.zigzag-timeline__item:nth-child(2n) {
    border-left: 1px solid #9ca3af;
}
.zigzag-timeline__item:nth-child(2n) .zigzag-timeline__milestone {
    left: 0;
    transform: translate(-50%, -50%);
}

/* Styles for odd items */
.zigzag-timeline__item:nth-child(2n + 1) {
    border-right: 1px solid #9ca3af;
}
.zigzag-timeline__item:nth-child(2n + 1) .zigzag-timeline__milestone {
    right: 0;
    transform: translate(50%, -50%);
}
```

```html index.html hidden
<div class="zigzag-timeline">
    <div class="zigzag-timeline__item">
        <div class="zigzag-timeline__milestone"></div>
        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>

        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>
    </div>

    <div class="zigzag-timeline__item">
        <div class="zigzag-timeline__milestone"></div>
        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>

        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>
    </div>

    <div class="zigzag-timeline__item">
        <div class="zigzag-timeline__milestone"></div>
        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>

        <div class="lines">
            <div class="line line--20"></div>
            <div class="line line--80"></div>
            <div class="line line--40"></div>
            <div class="line line--60"></div>
            <div class="line line--20"></div>
        </div>
    </div>
</div>
```
</Playground>
