jQuery UI Tabs organizes related content into a tab list and associated panels. It supports local panels, remote content, disabled tabs, collapsible behavior, show/hide effects and lifecycle events.
PHP runs on the server and can generate HTML or work with a database before the response reaches the browser.
HTML provides the document structure interpreted by the browser.
JavaScript runs in the browser and can update the interface after the page loads.
MySQL stores records that server-side code can query and update.
$( function () {
$( "#tabs" ).tabs({
heightStyle: "auto"
});
});
<div id="tabs">
<ul>
<li><a href="#php">PHP</a></li>
<li><a href="#html">HTML</a></li>
<li><a href="#js">JavaScript</a></li>
<li><a href="#mysql">MySQL</a></li>
</ul>
<div id="php">PHP content</div>
<div id="html">HTML content</div>
<div id="js">JavaScript content</div>
<div id="mysql">MySQL content</div>
</div>
Choose the active tab by zero-based index. With collapsible: true, active: false can start with all panels closed.
$( "#my_tabs" ).tabs({
active: 3
});
const activeIndex =
$( "#my_tabs" ).tabs( "option", "active" );
$( "#my_tabs" ).tabs( "option", "active", 1 );
$( "#my_tabs" ).tabs({
active: false,
collapsible: true
});
Demo: change active tab from radio buttons →
Demo: start with all panels collapsed →
Add or replace classes associated with Tabs structural elements.
$( "#my_tabs" ).tabs({
classes: {
"ui-tabs": "ui-state-highlight"
}
});
const currentClass =
$( "#my_tabs" ).tabs(
"option",
"classes.ui-tabs"
);
$( "#my_tabs" ).tabs(
"option",
"classes.ui-tabs",
"ui-state-error"
);
Demo: read and set Tabs classes →
Allow the active tab to be collapsed by activating it again.
const collapsible =
$( "#my_tabs" ).tabs(
"option",
"collapsible"
);
$( "#my_tabs" ).tabs(
"option",
"collapsible",
true
);
Disable all tabs with true or selected tabs with an array of indexes.
$( "#my_tabs" ).tabs({
disabled: [0, 3]
});
const disabledTabs =
$( "#my_tabs" ).tabs(
"option",
"disabled"
);
$( "#my_tabs" ).tabs(
"option",
"disabled",
[1, 3]
);
Demo: choose disabled tabs with checkboxes →
Choose the event that activates a tab. The default is click.
$( "#my_tabs" ).tabs({
event: "mouseover"
});
const eventName =
$( "#my_tabs" ).tabs(
"option",
"event"
);
$( "#my_tabs" ).tabs(
"option",
"event",
"click"
);
Demo: activate tabs with mouseover →
Control panel heights with content, fill, or auto.
$( "#my_tabs" ).tabs({
heightStyle: "fill"
});
const heightStyle =
$( "#my_tabs" ).tabs(
"option",
"heightStyle"
);
$( "#my_tabs" ).tabs(
"option",
"heightStyle",
"auto"
);
Control the animation used when a tab panel is hidden.
$( "#my_tabs" ).tabs({
hide: {
effect: "slide",
duration: 800
}
});
$( "#my_tabs" ).tabs(
"option",
"hide",
{
effect: "blind",
duration: 800
}
);
Control the animation used when a tab panel is shown.
$( "#my_tabs" ).tabs({
show: {
effect: "fade",
duration: 700
}
});
$( "#my_tabs" ).tabs(
"option",
"show",
{
effect: "fade",
duration: 600
}
);
Remove Tabs behavior and return the original markup.
$( "#my_tabs" ).tabs( "destroy" );
Disable the Tabs widget.
$( "#my_tabs" ).tabs( "disable" );
Enable a previously disabled Tabs widget.
$( "#my_tabs" ).tabs( "enable" );
Return the Tabs widget instance.
const instance = $( "#my_tabs" ).tabs( "instance" );
Load/reload a remote tab by index.
$( "#my_tabs" ).tabs( "load", 2 );
Read one option or the complete options object.
const active = $( "#my_tabs" ).tabs( "option", "active" );
const options = $( "#my_tabs" ).tabs( "option" );
Refresh Tabs after tabs/panels are added or removed directly in the DOM.
$( "#my_tabs" ).tabs( "refresh" );
Return the Tabs widget element as a jQuery object.
const widget = $( "#my_tabs" ).tabs( "widget" );
Fires after a tab is activated.
$( "#my_tabs" ).tabs({
activate: function ( event, ui ) {
console.log( ui.newTab.text() );
}
});
Fires before a tab changes. Returning false can cancel activation.
$( "#my_tabs" ).tabs({
beforeActivate: function ( event, ui ) {
console.log( "Changing tab" );
}
});
Fires before remote tab content is loaded.
$( "#my_tabs" ).tabs({
beforeLoad: function ( event, ui ) {
console.log( ui.ajaxSettings.url );
}
});
Fires when Tabs is initialized.
$( "#my_tabs" ).tabs({
create: function ( event, ui ) {
console.log( "Tabs created" );
}
});
The load event fires after remote tab content has loaded.
$( "#my_tabs" ).tabs({
load: function ( event, ui ) {
console.log( "Remote tab loaded" );
}
});
The original tutorial includes a theme-switching example.
Demo: Tabs with different jQuery UI themes →
Use normal CSS rather than putting JavaScript-style comments inside a CSS declaration.
.ui-tabs {
width: 800px; /* Change this value */
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.