Home  >  Q&A  >  body text

CSS: Keep HTML tags and hide only text content inside <a> tags

There is an "a" with an "img" inside it, followed by the text of the link. I need to hide these link text without hiding the "img" tag.

<a href="https://www.example.com/page">
    <img src="images/example.jpg" width="50" />
    This is a link
</a>

In this "a" tag, I need to hide the "This is a link" part and leave only the "img" tag to display. The HTML content cannot be changed (new HTML tags added or removed). How can I do this?

P粉973899567P粉973899567225 days ago407

reply all(1)I'll reply

  • P粉846294303

    P粉8462943032024-03-29 20:49:14

    Without knowing the rest of html or the use case, maybe you can just set the size of the a tag and font-size attribute to zero That’s it.

    a {
      font-size: 0;
      width: 0;
      height: 0;
    }
    
      
        This is a link
    

    reply
    0
  • Cancelreply