Floating Icon Bar with tooltips
Floating Icon Bar with tooltips
June 19, 2024

June 7, 2024

How to Hide Text in a Logo Using CSS

You might want to hide the text in a logo and show an image for several reasons:

  • SEO Benefits: Text content can be indexed by search engines, potentially improving the site’s search ranking. Search engines can’t “see” images but can read text, making the logo text useful for SEO purposes.
  • Accessibility: Screen readers, used by visually impaired users, can read text even if it’s not visually displayed on the screen. By keeping the text available but hidden, you ensure that all users, regardless of their abilities, can understand what the logo represents.
  • Design Consistency: Using images for logos ensures consistency in branding and design, especially across different platforms and devices. Images can maintain their appearance regardless of the browser or operating system.

CSS Technique for Hiding Text in a Logo

To hide the text of a logo and show a background image, you can use this CSS technique. This method uses text-indent to move the text out of the visible area and other properties to keep it hidden without affecting the layout.

<a href="#" class="logo">Company name</a>
a.logo {
    text-indent: -9999px;  /* Shifts the text far off-screen */
    overflow: hidden;      /* Ensures no overflow text is visible */
    white-space: nowrap;   /* Prevents text from wrapping to the next line */
    display: block;        /* Allows setting width and height */
    width: 150px;          /* Sets the width of the logo element */
    height: 50px;          /* Sets the height of the logo element */
    background-image: url('logo.png');  /* URL of the logo image */
    background-size: cover; /* Ensures the background image covers the entire area */
}

Explanation of the CSS Properties:

  1. text-indent: -9999px; – This property moves the text far off to the left, outside the visible area of the viewport. It effectively hides the text from sight.
  2. overflow: hidden; – This property ensures that any content that exceeds the boundaries of the element is hidden. It prevents any text that might accidentally appear due to layout changes.
  3. white-space: nowrap; – This property prevents the text from wrapping to the next line, which helps keep the text consistently hidden.

Summary

By using this CSS technique you can hide the text in a logo and show an image, and have a balance of design, SEO and accessibility. Some of you might say we could use:

visibility: hidden;

But with this method the logo text would still be in the visible part of the page and can still be selected. Our method ensures your brand logo looks good, is searchable and accessible to all users. Whether you’re designing a personal website or working on a big project, add this to your CSS arsenal and you’ll improve the overall functionality and user experience of your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

Level Up Your Coding Skills

Get the best CSS, HTML, and JS snippets delivered to your inbox monthly. 🚀
No spam—just coding gold! 💻✨"

We don’t spam! Read our privacy policy for more info.

cookie
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.
Read more