How to add a close icon in bootstrap tabs?

I want to add a close icon in bootstrap tabs and then I can close the tab by click the icon.

I try below but the “X” is displayed not on the same line as tab title.

.close {
    font-size: 20px;
    font-weight: bold;
    line-height: 18px;
    color: #000000;
    text-shadow: 0 1px 0 #ffffff;
    opacity: 0.2;
    filter: alpha(opacity=20);
    text-decoration: none;
.close:hover {
    color: #000000;
    text-decoration: none;
    opacity: 0.4;
    filter: alpha(opacity=40);
    cursor: pointer;

<a id="user-list-tab-li" style="display:inline;" href="#user-list-tab-pane">The tab</a> 
<span class="close">×</span>

the working fiddle is here

 function registerCloseEvent() {

$(".closeTab").click(function () {

    //there are multiple elements which has .closeTab icon so close the tab whose close icon is clicked
    var tabContentId = $(this).parent().attr("href");
    $(this).parent().parent().remove(); //remove li of tab
    $('#myTab a:last').tab('show'); // Select first tab
    $(tabContentId).remove(); //remove respective tab content


Try to put the span-tag inside the a-tag:

<a id="user-list-tab-li" style="display:inline;" href="#user-list-tab-pane">The tab<span class="close">×</span></a> 

And if you use bootstrap include an icon like this:

<i class="icon-remove"></i>

Small tweaks to Vinod Louis‘s answer – relative link to the li list and only show a tab if it is the current one closing.

function close_tab (tab_li)
    var tabContentId = $(tab_li).parent().attr("href");
    var li_list = $(tab_li).parent().parent().parent();
    $(tab_li).parent().parent().remove(); //remove li of tab
    if ($(tabContentId).is(":visible")) {
        li_list.find("a").eq(0).tab('show'); // Select first tab
    $(tabContentId).remove(); //remove respective tab content

Then attach:



<button class="close closeTab" type="button" onclick="close_tab(this)" >×</button>

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   How to make bootstrap tooltip remain visible till the link is clicked

Similar Posts