-1

In the Bootstrap CSS examples, all of the placeholder links have href="#".

I understand that href="#" provides a preventDefault()-like behavior, but without JS. Is there any other reason to use href="#"?

And if you're href="#" in this manner, isn't it more "correct" to use a <button> instead?

Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160

2 Answers2

1

I recommend MDN as a better resource for understanding HTML standards than the bootstrap examples. Bootstrap is often quite focused on mixing style into your HTML itself, and often shortcuts around the 'proper' way of doing things. That said, it's generally quite pretty and does a lot of things fast, and like anything in programming you can write good or bad code using it.

The 'href' attribute was a required attribute in previous HTML specs, so you would always need it. href="#" was a quick and dirty way of essentially omitting it. It's no longer required in the html5 spec, and without an href is specifically used to create placeholder links, as described here: https://developer.mozilla.org/en/docs/Web/HTML/Element/a

Josh from Qaribou
  • 6,776
  • 2
  • 23
  • 21
  • 1
    "without an href is specifically used to create placeholder links" It would actually be a hyperlink **target**. – André Dion Jun 04 '14 at 15:27
0

I like more w3c for those things, spite of MDN, (for standards I mean).

https://www.w3.org/TR/2012/WD-html5-20121025/links.html#attr-hyperlink-href

If it exists, it has to be a valid URL – But it is not a required attribute.

Marc.2377
  • 7,807
  • 7
  • 51
  • 95
miguel-svq
  • 2,136
  • 9
  • 11
  • An empty string is a valid URL according to the specs; see the other question this one's a duplicate of. – Marc.2377 May 17 '19 at 21:41