---
category: Input
created: '2019-11-17'
description: Create a slider with CSS flexbox
keywords: css flexbox, css slider
thumbnail: /assets/css-layout/thumbnails/slider.png
title: Slider
---

## HTML

```html index.html
<div class="slider">
    <!-- Left side -->
    <!-- Width based on the current value -->
    <div class="slider__left" style="width: 20%"></div>

    <!-- Circle -->
    <div class="slider__circle"></div>

    <!-- Right side -->
    <div class="slider__right"></div>
</div>
```

## CSS

```css styles.css
.slider {
    /* Content is centered horizontally */
    align-items: center;
    display: flex;

    /* Size */
    height: 2rem;
}

.slider__left {
    height: 2px;

    /* Colors */
    background-color: #d1d5db;
}

.slider__circle {
    /* Size */
    height: 2rem;
    width: 2rem;

    /* Rounded border */
    border-radius: 9999px;

    /* Colors */
    background-color: #3b82f6;
}

.slider__right {
    /* Take the remaining width */
    flex: 1;
    height: 2px;

    /* Colors */
    background-color: #d1d5db;
}
```

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

.slider {
    /* Content is centered horizontally */
    align-items: center;
    display: flex;

    /* Size */
    height: 2rem;

    /* Demo */
    width: 16rem;
}

.slider__left {
    height: 2px;

    /* Colors */
    background-color: #d1d5db;
}

.slider__circle {
    /* Size */
    height: 2rem;
    width: 2rem;

    /* Rounded border */
    border-radius: 9999px;

    /* Colors */
    background-color: #3b82f6;
}

.slider__right {
    /* Take the remaining width */
    flex: 1;
    height: 2px;

    /* Colors */
    background-color: #d1d5db;
}
```

```html index.html hidden
<div class="slider">
    <div class="slider__left" style="width: 20%"></div>
    <div class="slider__circle"></div>
    <div class="slider__right"></div>
</div>
```
</Playground>
