8

What's the difference between input[type=hidden] and visibility : hidden; ?

zx8754
  • 52,746
  • 12
  • 114
  • 209
meee meeee
  • 191
  • 1
  • 3
  • 15

4 Answers4

13

The first one is input element and the second is used for style in CSS2.

visibility: hidden; The visibility property specifies whether or not an element is visible.

input[type=hidden] :- HIDDEN is a TYPE attribute value to the INPUT element for FORMs. It indicates a form field that does not appear visibly in the document and that the user does not interact with. It can be used to transmit state information about the client or server.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
3

I’m assuming you mean what is the difference between <input type="hidden" /> and with CSS

.hidden {
    display: none;
}

If that’s the case then the first one is a DOM type but still in the structure, the second is a style method to remove the item from the DOM structure.

Phillip Berger
  • 2,317
  • 1
  • 11
  • 30
  • 5
    `display: none` doesn't remove the item from the DOM, it just keeps it from being rendered. – Barmar Sep 07 '13 at 15:36
  • 3
    `display:none` is not `visibility: hidden`, see: [What is the difference between visibility:hidden and display:none?](http://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone) – Luke Oct 27 '16 at 14:56
2

input[type=hidden] is definitely a selector, which matches every input element which has type attribute value set to hidden.

I have no idea what visibility="hidden" is. It could be CSS property, but incorrect one. It should be visibility: hidden; to be valid.

MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
2
input[type=hidden]

This is a DOM selector (jQuery, CSS, etc.) for any input elements where the type attribute is "hidden". It doesn't have anything to do with actually displaying or hiding those elements, aside from the fact that browsers don't render <input type="hidden" /> elements.

visibility="hidden"

This is setting the CSS visibility property to the value "hidden" which would tell the browser to not render whatever element(s) to which you're applying that attribute. This is entirely about display of HTML elements and doesn't have anything to do with selectors or form elements as the other example does.

David
  • 208,112
  • 36
  • 198
  • 279