Favorites

CSS Social Media Sidebar

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Social Media

What is a social media sidebar?

Social media is a big part of how people discover websites. A social media sidebar is a small column of icon buttons fixed to the side of the screen, linking to your social profiles. Because its position is fixed, it stays in the same place as visitors scroll, so the links are always within reach.

In this tutorial we'll build one with HTML and CSS. Each button shows an icon, and when you hover over it, a label slides out showing the name of the site.

Scroll the mini page below and notice the sidebar stays put. Hover over the buttons, or press Tab to move through them, to see the labels slide out:

Results

Scroll this box. The sidebar on the left stays in the same place while the text moves.

On a real website, the sidebar uses position: fixed, so it stays put while the whole page scrolls.

Hover over a button to see its label slide out to the right. Keyboard users get the same effect when they Tab to a button.

Each button has its own colour, set with a single custom property.

The icons are inline SVG, so they need no extra downloads and stay sharp at any size.

Keep scrolling: the sidebar is still there.

That's the whole idea. Now let's build it.

A better way to add icons

The original version of this tutorial used an icon font: a font where each "letter" is a picture, loaded from a free service called We Love Icon Fonts. That service has since closed down, and every icon that depended on it disappeared.

It's a good reminder of the risks of icon fonts in general:

  • They depend on a file loading. If the font fails to download, or the service closes, visitors see empty boxes or random letters.
  • They load every icon, even if you only use a handful.
  • They can confuse screen readers, which may try to read the hidden "letters" aloud.

Use inline SVG instead

SVG (Scalable Vector Graphics) is an image format written as code. You can paste an SVG straight into your HTML, where it becomes part of the page: nothing extra to download, nothing that can break, and it stays crisp at any size. With stroke="currentColor" or fill="currentColor", it even takes on the text colour you set in CSS.

<svg width="20" height="20" viewBox="0 0 24 24" fill="none"
     stroke="currentColor" stroke-width="2" aria-hidden="true">
  <rect x="3" y="5" width="18" height="14" rx="2"/>
  <path d="M3 7l9 6 9-6"/>
</svg>

Getting social network icons

Social network logos are trademarks, so the demos in this post use generic icons. For your own sidebar, download each network's official icon from its brand resources or press page (search for the network's name plus "brand guidelines"). These pages provide SVG files and explain how the logo may be used, such as approved colours and minimum sizes.

Open icon collections, such as Simple Icons, also gather many brand icons as SVG in one place. Whichever source you use, follow each brand's own guidelines.

Step 1: the HTML

The sidebar is a list of links inside a <nav> element. Each link contains an SVG icon and a <span> with the site's name:

<nav class="social-bar" aria-label="Follow us">
  <ul>
    <li>
      <a href="https://example.com/your-profile" style="--social-color: #1d4ed8;">
        <svg ... aria-hidden="true">...</svg>
        <span>Network name</span>
      </a>
    </li>
    <!-- one list item per network -->
  </ul>
</nav>
  • <nav> marks the sidebar as a group of navigation links, and aria-label="Follow us" gives screen readers a name for it.
  • The <ul> list tells screen reader users how many links there are.
  • The SVG has aria-hidden="true" because the <span> text already names the link.
  • style="--social-color: ..." sets each button's colour. We'll use it in step 3.

What changed since the old version? The original listed nine networks, including Google+ and StumbleUpon, which have both since closed, and misspelt Instagram's class as entypo-instagrem. It's worth reviewing your social links every so often to remove dead ones.

Step 2: fixing the sidebar in place

.social-bar {
  position: fixed;
  top: 50%;
  left: 0;
  translate: 0 -50%;
  z-index: 100;
}

.social-bar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
LineWhat it does
position: fixed;Attaches the sidebar to the browser window instead of the page, so it doesn't scroll away
top: 50%; and translate: 0 -50%;Centres the sidebar vertically, whatever the screen height. The original used a fixed top: 150px.
left: 0;Pins it to the left edge of the screen
z-index: 100;Keeps it on top of the page's other content
list-style: none;Removes the bullet points from the list. (See the list-style property.)

Tip: in the demo above, the sidebar uses position: sticky inside a scrolling box, so it stays in its frame instead of following you down this whole article. On your own site, use position: fixed as shown here.

Step 3: styling the buttons

.social-bar a {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: #ffffff;
  background: var(--social-color, #334155);
  text-decoration: none;
}

.social-bar li:first-child a { border-top-right-radius: 8px; }
.social-bar li:last-child a  { border-bottom-right-radius: 8px; }
  • display: grid with place-items: center centres the icon perfectly in the square.
  • Buttons are 44px square, a comfortable size to tap. The original's 35px was a little small.
  • background: var(--social-color, #334155) uses each link's own colour, with a dark grey fallback if none is set.
  • The first and last buttons get rounded outer corners, so the whole bar looks like one tidy shape.

Using a custom property for the colour replaces 27 lines of the original CSS, three rules per network, with one small style on each link.

Tip: if you use each network's brand colour, check that white icons and text are readable against it, with a contrast ratio of at least 4.5 to 1 for the labels. Some brand colours are quite light, and may need a darker shade or dark text instead.

Step 4: the sliding labels

Finally, the name of each site slides out to the right when you hover over its button. The label sits just to the right of the button, hidden by clip-path until it's needed:

.social-bar a span {
  position: absolute;
  top: 0;
  left: 100%;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 14px;
  white-space: nowrap;
  font: 600 14px/1 system-ui, sans-serif;
  background: inherit;
  border-radius: 0 8px 8px 0;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.25s ease;
}

.social-bar a:hover span,
.social-bar a:focus-visible span {
  clip-path: inset(0);
}

How it works

  • left: 100% places the label immediately to the right of its button.
  • background: inherit takes the button's colour, so each label matches its button automatically.
  • clip-path: inset(0 100% 0 0) cuts away 100% of the label from the right, hiding it completely. On hover, inset(0) cuts nothing, and the transition animates the label revealing itself from left to right.
  • white-space: nowrap keeps longer names on one line.

Why clip-path? The original hid each label off the screen with left: -120px and jumped it into place on hover, with no animation. clip-path animates smoothly, and because the label is only visually hidden, screen readers can still read it as the link's name.

Phones, keyboards and accessibility

Move the bar to the bottom on small screens

On a phone, a sidebar fixed to the edge of the screen covers part of the content, and there's no hover to reveal the labels. A common solution is to turn it into a bar along the bottom of the screen instead:

@media (max-width: 600px) {
  .social-bar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    translate: none;
  }
  .social-bar ul { display: flex; }
  .social-bar li { flex: 1; }
  .social-bar a  { width: 100%; border-radius: 0 !important; }
  .social-bar a span {
    /* hide the sliding label visually, but keep it for screen readers */
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
}

Here's how that looks:

Results
Page content on a phone…

If the bottom bar covers the end of your page, add some padding-bottom to the <body> on small screens to make room for it.

Keyboard users

Pairing :hover with :focus-visible means keyboard users see the labels slide out as they Tab through the buttons. The orange outline shows which button is focused.

Opening in a new tab

The original opened every link in a new tab with target="_blank". That's common for social links, but it can be confusing, especially for screen reader users, who may not realise a new tab has opened. If you do use it, consider adding "(opens in a new tab)" to each label, and keep rel="noopener" on the link for security.

Reduced motion

@media (prefers-reduced-motion: reduce) {
  .social-bar a span {
    transition: none;
  }
}

The complete code

.social-bar {
  position: fixed;
  top: 50%;
  left: 0;
  translate: 0 -50%;
  z-index: 100;
}

.social-bar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.social-bar a {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: #ffffff;
  background: var(--social-color, #334155);
  text-decoration: none;
}
.social-bar li:first-child a { border-top-right-radius: 8px; }
.social-bar li:last-child a  { border-bottom-right-radius: 8px; }

.social-bar a span {
  position: absolute;
  top: 0;
  left: 100%;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 14px;
  white-space: nowrap;
  font: 600 14px/1 system-ui, sans-serif;
  background: inherit;
  border-radius: 0 8px 8px 0;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.25s ease;
}
.social-bar a:hover span,
.social-bar a:focus-visible span { clip-path: inset(0); }

.social-bar a:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: -3px;
}

@media (max-width: 600px) {
  .social-bar { top: auto; bottom: 0; left: 0; right: 0; translate: none; }
  .social-bar ul { display: flex; }
  .social-bar li { flex: 1; }
  .social-bar a  { width: 100%; border-radius: 0 !important; }
  .social-bar a span { clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .social-bar a span { transition: none; }
}

Wrapping up

A fixed list of icon links, a custom property for each colour and a clip-path label that slides out on hover or focus: that's a complete social media sidebar. Use inline SVG icons so nothing can break, get official logos from each network's brand resources, and switch to a bottom bar on phones so the sidebar never gets in the way.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee