20

I'll be completing a website soon for my university (in fact, it's mostly finished now other than some mild tweaking) and I'd like to add a hidden thank-you to some bloggers who helped, and the stack overflow community which was a huge help. Right now, I've got a text section which is hidden this way:

<font style="font-size:0px"> - text </font>

But I feel like there's probably a better way. Is there?

  • 5
    Font tag is deprecated... don't use it. – MikeSmithDev Apr 18 '13 at 13:01
  • ya use

    tag instead...

    – TDsouza Apr 18 '13 at 13:02
  • 2
    Did your university tell you to use ``? –  Apr 18 '13 at 13:03
  • I think you are looking for `display: none;` also you should have `font-size:0px;` not `font-size=0px` – Andrew Apr 18 '13 at 13:04
  • 8
    If it's not visible anyway, why not put it in a comment (``)? – Antony Apr 18 '13 at 13:04
  • @Antony - Because the CMS that they use strips out comments, so they won't even appear in the HTML. –  Apr 18 '13 at 13:16
  • @Chris - No, I just did it as a quick way to hide the text block. –  Apr 18 '13 at 13:16
  • @Andrew - You're right, that's what I used, I just typed it incorrectly here. –  Apr 18 '13 at 13:17
  • 1
    @ZacBrown ah ok. Good. I was helping a guy not so long ago who was studying web design and he told me his tutor told him to us `bgcolor`, ``. It was horrific. It really makes me question web courses in the UK. –  Apr 18 '13 at 13:18
  • 1
    @Chris Marquee? Really? I've not seen that since my first Angelfire site like....15 years ago? HAHAHAH ;-) –  Apr 18 '13 at 13:20
  • If it is to be hidden, why put it there at all? But even technically, this isn’t a real question. Hidden in what sense? Should be visible when style sheets are turned off? To search engines? To anyone who does View Source? In which sense should the information be there at all? As metadata? For which purpose and for which software? – Jukka K. Korpela Apr 18 '13 at 13:58
  • Good questions @JukkaK.Korpela. University policy is such that non-approved text,images,links, etc can't appear publicly anywhere on the domain and the dedication to all who have helped doesn't really fit with any of the content so there's nowhere for it to go. Essentially, I'd just like for the text to not be visible on the site, within the source code is fine. So, what I mean is, I'd like the text to exist, but not necessarily be displayed on the site itself, and not simply be a .txt file in the directory. –  Apr 18 '13 at 14:44

9 Answers9

21

This will keep its space, but not show anything;

opacity: 0.0;

This will hide the object fully, plus its (reserved) space;

display: none;
18
<div style="display:none;">CREDITS_HERE</div>
Lowkase
  • 5,631
  • 2
  • 30
  • 48
4

you can use css property to hide style="display:none;"

<div style="display:none;">CREDITS_HERE</div>
PSR
  • 39,804
  • 41
  • 111
  • 151
4

You said that you can’t use HTML comments because the CMS filters them out. So I assume that you really want to hide this content and you don’t need to display it ever.

In that case, you shouldn’t use CSS (only), as you’d only play on the presentation level, not affecting the content level. Your content should also be hidden for user-agents ignoring the CSS (people using text browsers, feed readers, screen readers; bots; etc.).

In HTML5 there is the global hidden attribute:

When specified on an element, it indicates that the element is not yet, or is no longer, directly relevant to the page's current state, or that it is being used to declare content to be reused by other parts of the page as opposed to being directly accessed by the user. User agents should not render elements that have the hidden attribute specified.

Example (using the small element here, because it’s an "attribution"):

<small hidden>Thanks to John Doe for this idea.</small>

As a fallback (for user-agents that don’t know the hidden attribute), you can specify in your CSS:

[hidden] {display:none;}

An general element for plain text could be the script element used as "data block":

<script type="text/plain" hidden>
Thanks to John Doe for this idea.
</script>

Alternatively, you could also use data-* attributes on existing elements (resp. on new div elements if you want to group some elements for the attribution):

<p data-attribution="Thanks to John Doe for this idea!">This is some visible example content …</p>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
  • Thanks @Unor. I think the –  Apr 18 '13 at 14:51
  • I added another way: using `data-*` attributes on existing elements. – unor Apr 18 '13 at 15:28
2

display: none or visibility: hidden.

jgillich
  • 71,459
  • 6
  • 57
  • 85
  • Visbility isn't supported very well. Beter to use opacity. –  Apr 18 '13 at 13:02
  • Don't assume I'm just talking about IE :P –  Apr 18 '13 at 13:04
  • 2
    @Allendar Then why don't you tell me what you are talking about? – jgillich Apr 18 '13 at 13:05
  • The DOM-object will lose it's event and tab-order bindings (or at least; make them temporary unresponsive). That might cause brain-breaking cases where one doesn't understand why the reserved area doesn't respond when you try to click/hover etc. That's what I'm talking about. (?) –  Apr 18 '13 at 13:11
2

Here are two ways you can achieve this

You can display none or have a opacity none...But if you want the opacity to be cross browser compatible you would have to add this to your css

/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

/* IE 5-7 */
filter: alpha(opacity=50);

/* Netscape */
-moz-opacity: 0.5;

/* Safari 1.x */
-khtml-opacity: 0.5;

/* Good browsers */
opacity: 0.5;

http://codepen.io/anon/pen/Krkfj

Antony
  • 14,900
  • 10
  • 46
  • 74
Steven
  • 817
  • 1
  • 8
  • 25
1

Not sure if this was what you were asking for, but I was personally trying to 'hide' some info in my html so that if someone inspected it, they would see the text in the source code.

It turns out that you can add ANY attribute, and so long as it isn't understood by the browser, it will just be left buried in the tag. My code was an easter egg: For people who couldn't afford to do the Makers Academy course, I basically encouraged them to inspect the element, where they would be given a secret URL where they could apply for a special, cut-price course (it's in haml, but it's the same idea in HTML):

.entry
        %h2 I can't afford to do the course... What should I do?
        %p{:url_you_should_visit => 'http://ronin.makersacademy.com'} Inspect and you shall find.

Or in html:

<p url_you_should_visit="http://ronin.makersacademy.com">Inspect and you shall find.</p>

Because 'url' is not a recognised html attribute, it makes no difference but is still discoverable. You could do the same with anything you wanted. You could have an attribute (in html) like:

<p thanks="Thanks to all the bloggers that helped me"> Some text </p>

And they'll be able to find your little easter egg if they want it... Hope that helps - it certainly helped me :)

Jordan Poulton
  • 313
  • 1
  • 2
  • 10
0

Use the CSS property visibility and set it to hidden.

You can see more here.

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
joseph
  • 298
  • 1
  • 4
  • 13
0

use css property style="display:none" or style=visibility:hidden"

mmpatel009
  • 921
  • 4
  • 11
  • 25