---
category: Display
created: '2019-11-21'
description: Create a separator with CSS flexbox
keywords: css divider, css flexbox, css separator
thumbnail: /assets/css-layout/thumbnails/separator.png
title: Separator
---

## HTML

```html index.html
<div class="separator">
    <!-- Text -->
    <div class="separator__content">...</div>

    <!-- Separator line -->
    <div class="separator__separator"></div>
</div>
```

## CSS

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

    /* Used to set the position of text */
    position: relative;
}

.separator__content {
    /* We won't see the separator line */
    background: #fff;

    /* Displayed at the center of separator */
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);

    /* Spacing */
    padding: 0 0.25rem;

    /* Demo */
    width: 60%;
}

.separator__separator {
    border-bottom: 1px solid #d1d5db;
    height: 1px;
    width: 100%;
}
```

<Playground>
```css placeholders.css hidden
.rectangle {
    background: #d1d5db;
    border-radius: 0.25rem;
    height: var(--rectangle-height);
    width: var(--rectangle-width);
}
.rectangle--hor.rectangle--20 {
    --rectangle-width: 20%;
}
.rectangle--hor.rectangle--40 {
    --rectangle-width: 40%;
}
.rectangle--hor.rectangle--60 {
    --rectangle-width: 60%;
}
.rectangle--hor.rectangle--80 {
    --rectangle-width: 80%;
}
.rectangle--hor.rectangle--100 {
    --rectangle-width: 100%;
}
.rectangle--hor.rectangle--sm {
    --rectangle-height: 0.5rem;
}
.rectangle--hor.rectangle--md {
    --rectangle-height: 2rem;
}
.rectangle--hor.rectangle--lg {
    --rectangle-height: 4rem;
}
.rectangle--ver.rectangle--20 {
    --rectangle-height: 20%;
}
.rectangle--ver.rectangle--40 {
    --rectangle-height: 40%;
}
.rectangle--ver.rectangle--60 {
    --rectangle-height: 60%;
}
.rectangle--ver.rectangle--80 {
    --rectangle-height: 80%;
}
.rectangle--ver.rectangle--100 {
    --rectangle-height: 100%;
}
.rectangle--ver.rectangle--sm {
    --rectangle-width: 0.5rem;
}
.rectangle--ver.rectangle--md {
    --rectangle-width: 2rem;
}
.rectangle--ver.rectangle--lg {
    --rectangle-width: 4rem;
}
```

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

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

    /* Used to set the position of text */
    position: relative;

    /* Demo */
    width: 20rem;
}

.separator__content {
    /* We won't see the separator line */
    background: #fff;

    /* Displayed at the center of separator */
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);

    /* Spacing */
    padding: 0 0.25rem;

    /* Demo */
    width: 60%;
}

.separator__separator {
    border-bottom: 1px solid #d1d5db;
    height: 1px;
    width: 100%;
}
```

```html index.html hidden
<div class="separator">
    <div class="separator__content"><div class="rectangle rectangle--hor rectangle--sm rectangle--100"></div></div>
    <div class="separator__separator"></div>
</div>
```
</Playground>
