debian-mirror-gitlab/doc/development/new_fe_guide/style/html.md

54 lines
1.3 KiB
Markdown
Raw Normal View History

2018-03-27 19:54:05 +05:30
# HTML style guide
2018-05-09 12:01:36 +05:30
## Buttons
2019-07-07 11:18:12 +05:30
### Button type
2018-05-09 12:01:36 +05:30
2019-07-07 11:18:12 +05:30
Button tags requires a `type` attribute according to the [W3C HTML specification](https://www.w3.org/TR/2011/WD-html5-20110525/the-button-element.html#dom-button-type).
```html
2018-05-09 12:01:36 +05:30
// bad
<button></button>
// good
<button type="button"></button>
```
2019-07-07 11:18:12 +05:30
### Button role
2019-05-18 00:54:41 +05:30
2019-07-07 11:18:12 +05:30
If an HTML element has an `onClick` handler but is not a button, it should have `role="button"`. This is [more accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role).
```html
2018-05-09 12:01:36 +05:30
// bad
<div onClick="doSomething"></div>
// good
<div role="button" onClick="doSomething"></div>
```
## Links
2019-07-07 11:18:12 +05:30
### Blank target
2019-05-18 00:54:41 +05:30
2019-07-07 11:18:12 +05:30
Use `rel="noopener noreferrer"` whenever your links open in a new window, i.e. `target="_blank"`. This prevents a security vulnerability [documented by JitBit](https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/).
```html
2018-05-09 12:01:36 +05:30
// bad
<a href="url" target="_blank"></a>
// good
<a href="url" target="_blank" rel="noopener noreferrer"></a>
```
2019-07-07 11:18:12 +05:30
### Fake links
2019-05-18 00:54:41 +05:30
2019-07-07 11:18:12 +05:30
**Do not use fake links.** Use a button tag if a link only invokes JavaScript click event handlers, which is more semantic.
```html
2018-05-09 12:01:36 +05:30
// bad
<a class="js-do-something" href="#"></a>
// good
<button class="js-do-something" type="button"></button>
```