The HTML specification indicates that a TAB char should be treated as a single empty space, unless it is contained within a <pre> element.
The code you posted above works and it inserts a TAB char, but it just displays as a space in the browser. If you can put all editable content in the <pre> tag , your tabs will appear.
If you want to use tabs for indentation content, you can also view
execCommand('indent', false, null)
source share