gpt-4.1-mini-2025-04-14· OpenAI WildChat-4.8M (AI2)
write a html css sticky social icons bar code for a website page
- User
write a html css sticky social icons bar code for a website page
- Assistant
Certainly! Here's a simple example of a sticky social icons bar that stays fixed on the left side of the screen as you scroll. It includes some common social media icons with hover effects.
Features:
- Sticky/fixed position vertically centered
- Icons with background colors for different social platforms
- Hover effect to expand each icon label
- Responsive for different screen sizes
Complete HTML + CSS Code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Sticky Social Icons Bar</title> <style> /* Reset some defaults */ body { margin: 0; font-family: Arial, sans-serif; } /* Container for the sticky bar */ .social-bar { position: fixed; top: 50%; left: 0; transform: translateY(-50%); display: flex; flex-direction: column; z-index: 1000; } /* Each social link */ .social-bar a { display: flex; align-items: center; color: white; text-decoration: none; padding: 12px; width: 50px; /* default width - just icons */ transition: width 0.3s ease; overflow: hidden; white-space: nowrap; border-radius: 0 5px 5px 0; margin: 4px 0; font-weight: bold; } /* Expand on hover to show label */ .social-bar a:hover { width: 150px; } /* Icon inside the link */ .social-bar a .icon { font-size: 20px; margin-right: 10px; min-width: 20px; text-align: center; } /* Labels (hidden initially behind small width) */ .social-bar a span { pointer-events: none; } /* Social colors */ .social-bar a.facebook { background: #3b5998; } .social-bar a.twitter { background: #1da1f2; } .social-bar a.linkedin { background: #0077b5; } .social-bar a.instagram { background: #e4405f; } .social-bar a.github { background: #333; } /* Optional: Tooltip for accessibility */ .social-bar a[aria-label]:hover::after { content: attr(aria-label); position: absolute; left: 60px; background: rgba(0,0,0,0.7); color: #fff; padding: 3px 8px; border-radius: 3px; font-size: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; white-space: nowrap; } </style> <!-- Use Font Awesome CDN for icons --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" /> </head> <body> <div class="social-bar" aria-label="Social Media Links"> <a href="https://facebook.com" class="facebook" target="_blank" rel="noopener" aria-label="Facebook"> <i class="fab fa-facebook-f icon" aria-hidden="true"></i><span>Facebook</span> </a> <a href="https://twitter.com" class="twitter" target="_blank" rel="noopener" aria-label="Twitter"> <i class="fab fa-twitter icon" aria-hidden="true"></i><span>Twitter</span> </a> <a href="https://linkedin.com" class="linkedin" target="_blank" rel="noopener" aria-label="LinkedIn"> <i class="fab fa-linkedin-in icon" aria-hidden="true"></i><span>LinkedIn</span> </a> <a href="https://instagram.com" class="instagram" target="_blank" rel="noopener" aria-label="Instagram"> <i class="fab fa-instagram icon" aria-hidden="true"></i><span>Instagram</span> </a> <a href="https://github.com" class="github" target="_blank" rel="noopener" aria-label="GitHub"> <i class="fab fa-github icon" aria-hidden="true"></i><span>GitHub</span> </a> </div> <!-- Dummy content to test scrolling --> <main style="padding: 20px;"> <h1>Page Content</h1> <p>Scroll down to see the sticky social icons bar stay in place.</p> <p style="height: 1500px;">(Dummy space for scrolling)</p> </main> </body> </html>
Explanation:
- Positioning:
.social-baris fixed on the left and vertically centered usingtop: 50%andtransform: translateY(-50%). - Icon fonts: We use Font Awesome for clean icons (loaded via CDN). You can replace with your own icons or SVGs.
- Hover effect: The bar starts narrow (icon only) and expands to show the text label on hover.
- Accessibility:
aria-labels are added for screen readers. - Links: Open in a new tab with
target="_blank"andrel="noopener"for safety.
Feel free to customize colors, icons, sizes, or position based on your website style! Let me know if you want a vertical bar at the bottom, top, right, or something else.