Using the jQuery UI Tabs widget

Title 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque enim leo, varius ac egestas in, blandit quis massa. Vestibulum dapibus quam non libero convallis at pulvinar magna porttitor. In eget magna erat. Donec tempus, nisl vel egestas iaculis, velit neque scelerisque augue, vel pulvinar ante nunc ac turpis. Donec nec risus at est suscipit dictum quis in justo. Pellentesque neque nulla, vestibulum pharetra ultricies sit amet, ullamcorper id erat. Mauris ante nisi, vestibulum ac ullamcorper in, suscipit vitae ante. In ut sem odio. Phasellus gravida, sapien a interdum tincidunt, dui neque venenatis diam, nec tincidunt risus est in nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean ullamcorper vulputate nisi nec vestibulum.

Title 2

Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.

Title 3

Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.

Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.

Title 4

Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.

jQuery UI is a branch of the jQuery project. Rather than simply providing a library of JavaScript functions, UI provides entire widgets which comprise of two JavaScript files, the core jQuery library, plus a specific JavaScript library for the UI widget(s) you are using, the associated CSS for the widget and any image files used for the widget. It's a one-stop solution but it can be styled exactly how you want it by editing the images and CSS.

Here's the script and CSS link:

<!-- load CSS for Tabs from jQuery CDN -->
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/
jquery-ui.css" "rel=stylesheet"> <!-- load jQuery and jQuery UI from jQuery CDN --> <script src="https://code.jquery.com/jquery-1.9.1.js"></script> <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $("#tabs").tabs(); }); </script>

We are loading 3 files from the jQuery Content Delivery Network. First, the CSS for the Tabs widget is linked. Here we're using the "Smoothness" theme (one of many available). The next file loaded is the core jQuery library. The third is the jQuery UI library and finally, a simple script is required to make the tabs work.

See the jQuery UI Demos page for more information on what jQuery UI can do and the jQuery UI Tabs page for details of this widget.

Note: In this example, the script is shown as it would appear if placed in the HTML file and is done only for convenience in demonstrating how it works. The best practice solution would be to place the script in an external file and call it like this:

<script src="filename.js"></script>

jQuery selectors work in exactly the same way as CSS selectors, so the script will work just as well from an external .js file as it will from the .html file.