0

MDN says:

This is quite different from using the CSS property display to control the visibility of an element.

I do notice though when I make an element hidden it gets display: none;.

In what ways is .hidden = true different to setting display: none;?

tonitone120
  • 1,920
  • 3
  • 8
  • 25

2 Answers2

2

One is HTML, the other is CSS. HTML is for semantics, whereas CSS is for styling. Some HTML elements and properties happen to come with default styles, depending on the user agent.

So it's like the difference between <strong> (which is shown bold by default in most user agents) and <span style="font-weight: bold">.

Lionel Rowe
  • 5,164
  • 1
  • 14
  • 27
-3

Ultimately, what it boils down to is:

display:none completely hides the element from the page. It isn't rendered. You can still interact with it through the DOM, but there is no space allocated for it and it doesn't affect any other elements on the page visually.

visibility:hidden only hides the element but the space remains. It affects other elements on the page. You can't see it but you can see its space

E_net4
  • 27,810
  • 13
  • 101
  • 139
QT Ray
  • 1,256
  • 8
  • 12
  • It’s being downvoted because you answered the difference between `display: none` and `visibility: hidden` when the question was about the difference between `display: none` and the `hidden` HTML attribute. – Ry- Sep 23 '20 at 22:55