Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3852850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:22:45+00:00 2026-05-19T17:22:45+00:00

Is there a way of hiding an element’s contents, but keep its :before content

  • 0

Is there a way of hiding an element’s contents, but keep its :before content visible?
Say I have the following code:

HTML:

<span class="addbefore hidetext">You are here</span>

CSS:

.addbefore:before {
    content: "Show this";
}
.hidetext {
    // What do I do here to hide the content without hiding the :before content?
}

I’ve tried:

  • using display: none and setting display: inline on :before, but both are still hidden
  • using width: 0; overflow: hidden;, but then additional space seems to be added (?)
  • using color: transparent;, but then, of course, the content of the span still takes up space
  • using text-indent: -....px, but
    1. this is frowned upon by search engines and
    2. it seems not to work for span elements (?)

Any other ideas as to how I might do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:22:45+00:00Added an answer on May 19, 2026 at 5:22 pm

    Clean Solution

    You could use visibility: hidden, but with this solution, the hidden content will still take up space. If this doesn’t matter to you, this is how you would do it:

    span {
        visibility: hidden;
    }
    
    span:before {
        visibility: visible;
    }
    

    Hackish Alternative Solution

    Another solution would be to set the font-size of the span to zero* to a really small value. Advantage of this method: The hidden content won’t take up any space. Drawback: You won’t be able to use relative units like em or % for the font-size of the :before content.

    span:before {
        content: "Lorem ";
        font-size: 16px;
        font-size: 1rem; /* Maintain relative font-size in browsers that support it */
        letter-spacing: normal;
        color: #000;
    }
    
    span {
        font-size: 1px;
        letter-spacing: -1px;
        color: transparent;
    }
    

    Example on jsfiddle.

    Update (May 4, 2015): With CSS3, you can now use the rem (Root EM) unit to maintain relative font-sizes in the :before element. (Browser support.)


    *A previous version of this post suggested setting the font size to zero. However, this does not work as desired in some browsers, because CSS does not define what behavior is expected when the font-size is set to zero. For cross-browser compatibility, use a small font size like mentioned above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in jQuery where I can hide an element, but not
What would be the preferred way of hiding an element before the page is
Is there way to copy a file into Plone with WebDAV and have Plone
I have a way of hiding the back button used by the navigation controller.
Hi is there any way to detect iPad keyboard hiding button ? i mean
Is there a way to start off showing a dialog modally, but then instead
Is there way to get file from windows xp command prompt? I tried to
Is there way to automatically maximize the output window on hitting build and then
is there way how to get name ov event from Lambda expression like with
Is there way to better identify design pattern in source codes, esp. if you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.