• Molecule
  • CORE COMPONENT
  • Taxonomic name: M-TABS
  • Added on: v3.0.0 (15/09/17)
  • Updated on: v5.9.0 (13/07/21)

Tabs

Tabs allow users to quickly switch between large linked areas of content. This section variant is used within the main flow of content when there is a need to chuck information into different aspects within a topic.


Design and usage

Placement

  • Consider how you denote the bottom or end of the tab content to avoid confusion with content that might sit below the tabs. For example, add a keyline at the bottom of the tab.

Structure

  • Tabs should be ordered left to right in order of priority.
  • Based on the device width, as many tabs as will fit will be displayed. Once tab labels are too wide, they will be displayed as part of a scrollable carousel; this carousel is swipeable as well as having forward / backward buttons which also help with informing users that extra items are available to view.
  • Do not attempt to mix and match tabs styles with a group (for example, one tab with a sub-heading and one with an icon). You can, however, have one set of tabs using sub-headings and another elsewhere on the page using icons.
  • Do not use section tabs on any background colour other than white.

Labels

  • Keep labels simple and short - no more than two or three words long and clearly describe the destination content.

Use case and exception scenarios

  • Use within sections of a page with multiple sections of content.
  • Do not use tabs when there would be more than six tabs in a group.
  • Do not use tabs when a user needs to see all the information contained within them in the same view (eg. when making comparisons).

Examples

Standard section tabs

  • Standard tabs should be used by default.
  • All the content is loaded during page load and hidden using JavaScript behind tabs.
  • For non-JavaScript, all tab content is loaded running down the page with the tab headings reverting to a H3 heading with a full width keyline followed by the relevant content block.

Interactive example

Code example

<div class="m-tabs [ Modifiers ]" data-module="m-tabs" data-module-load="true">
	<h3 class="a-heading a-heading--3 a-heading--light m-tabs__heading">
		...
		<span class="m-tabs__sub-heading">...</span>
	</h3>
	<div class="m-tabs__content">
		...
	</div>
</div>

Nested tabs

  • If section tabs are placed within section tabs, they will automatically be styled as nested tabs. It is also possible to style section tabs as nested tabs outside of other tabs if required.
  • Only standard tabs can be used when nesting section tabs.
  • Nested tabs must not include icons or sub-headers within the tab heading.
  • Do not use lazy loading section tabs within a nested tab.

Tabs with sub-headings

  • Optional sub-headings can be applied to tabs, but must not be used in conjunction with icons within the tab heading.

Interactive example

Code example

<div class="m-tabs [ Modifiers ]" data-module="m-tabs" data-module-load="true">
	<h3 class="a-heading a-heading--3 a-heading--light m-tabs__heading">...<span class="m-tabs__subheading">[ optional subheading ]</span></h3>
	<div class="m-tabs__content">
		...
	</div>
</div>

Tabs with icons

  • Each icon should be made up as a single sprite with a fixed size of 156px x 50px, with the three versions of the individual icons (grey, blue and white) within it being no more than 50px square and centred horizontally at 26px, 78px and 130px (for sprites made up with icons with a 1:1 ratio icon, this will leave 1px blank space on either side of each icon within the sprite).

    Tab icon sprite example - car insurance
    Tab icon sprite example - car insurance
    Tab icon sprite example - spacing
    Tab icon sprite example - with visible indicators to show blank space either side of icons
  • Icons must not be used in conjunction with sub-headers within the tab heading.

Interactive example

Code example

<div class="m-tabs [ Modifiers ]" data-module="m-tabs" data-module-load="true">
	<h3 class="a-heading a-heading--3 a-heading--light m-tabs__heading">
	<span class="m-tabs-icon">
		<img src="..." decoding="async" width="156" height="150" alt="" />
	</span>...</h3>
	<div class="m-tabs__content">
		...
	</div>
</div>

Tabs with lazy-loaded content

  • These tabs should be used when you need to load each tab separately because of heavy page load times or backend constraints.
  • They are poor for search engine optimisation (SEO) needs and should not be used if SEO is important to your customer experience (eg. product pages).
  • For non-JavaScript, tab headings revert to a list of styled links which send users to static pages containing the content for the relevant tab.

Interactive example

Code example

<div class="m-tabs m-tabs--links m-tabs--links-lazy" data-module="m-tabs" data-module-load="true">
	<div class="m-tabs__list">
		<ul class="a-list-plain">
			<li><a href="..." class="a-heading a-heading--3 a-heading--light m-tabs__heading">...</a></li>
			<li><a href="..." class="a-heading a-heading--3 a-heading--light m-tabs__heading">...</a></li>
			...
		</ul>
	</div>
	<div class="m-tabs__content" id="...">
		<h3 class="a-heading a-heading--3 a-heading--light m-tabs__heading">...</h3>
		...
	</div>
</div>

Development and test

Notes for developers

By default the first section tab will be opened on page load. This can be changed if required by applying js-m-tab-open to any m-tabs__heading.

A section tab can be linked to and automatically opened by adding an ID to any .m-tabs__heading

Sub-headings

Optional sub headers can be applied to section tabs when wrapped in a span using the .m-tabs__sub-heading class.

Icon tabs

Optional icons can be applied to both primary or section tabs when wrapped in a span using the .m-tabs-icon class.

Nested tabs

Nested tabs are tabs that sit within the content of primary or section tabs. As such, nested tabs will be automatically styled as secondary tabs when the style .m-tabs is a descendant of another instance of .m-tabs. They can also be styled independently using the modifier class m-tabs--nested.

Printing

It is possible to force the printing of all tab sections through the use of the modifier class m-tabs--print. This should only ever be used to satisfy legal requirements for all information to be available when printed. The use of this feature should always be challenged, as if the content if legally important, it should probably not be hidden within tabs in the first place.

Controling tabs programatically

Section tabs can be controlled programatically to open a specified tab and optionally scroll to it.

Method Description
open( '#headingId' ) Open the tab associated with the content ID provided. This will not open any parent tabs and will not scroll the content into view.
open( '#headingId', true ) Open the tab associated with the content ID provided. Any parent tab sections will be opened and the content will be scrolled into view.

For example:

document.addEventListener( 'frameworkready', function () {
	FRAMEWORK.require([ 'blocks/m-tabs' ], function ( mTabsModule ) {
		var mTabsEl = document.querySelector( '#tabsId' ),
			mTabsInstance = mTabsModule.initInstance( mTabsEl );		mTabsInstance.open( '#tabHeadingId', true );
	});
});

Changing locale settings

Locale settings should be updated to include appropriate translations for the 'Previous' and 'Next' messages to accompany the carousel arrows, and also for the message on the loading indicator for the tabs with lazy-loading content.

en: {
	mTabs : {
		previousText : 'Previous',
		nextText : 'Next',
		loadingText : 'Please wait',
	},
},

For more information on this, see our page on how to change locale settings within JavaScript.


Notes for testers

  • Ensure that links can be accessed via the mouse as well as via tabbing using the keyboard.
  • Use a screen reader to confirm that the links are understandable as to where they will be going when listed out of context of the page.
  • Ensure that when hovering over a link the style changes noticeably.
  • Ensure that when a link has focus the style changes noticeably.
  • There should be a clear visual distinction between the currently selected tab and the others.
  • The whole of the tab must look and be clickable.
  • When JavaScript is not available, the tabs should fall back to being headings followed by content. Tabs with lazy-loading content should display a list of links followed by a single heading and content block relevant to the currently selected tab.

Classes overview

The following table gives you a quick overview of the CSS classes that can be applied.

Class Outcome Required Applied to Comments
.m-tabs Base style for section tab areas Yes div  
.m-tabs--print Modifier to force the print of all tab sections   .m-tabs  
.m-tabs--nested Modifier style for section tab areas to make them smaller   .m-tabs  
.m-tabs--links Modifier style for section tab areas for lazy-load tabs   .m-tabs  
.m-tabs__heading Base style for section tab heading Yes .m-tabs > h1, .m-tabs > h2, .m-tabs > h3, .m-tabs > h4  
.m-tabs__sub-heading Used to style sub headers   .m-tabs > h1 > span, .m-tabs > h2 > span, .m-tabs > h3 > span, .m-tabs > h4 > span Apply sub headers within the header tag wrapped in a span using the .m-tabs__sub-heading class.
.m-tabs-icon Used to style icons within headers   .m-tabs > h1 > span, .m-tabs > h2 > span, .m-tabs > h3 > span, .m-tabs > h4 > span Apply icons within the header tag wrapped in a span using the .m-tabs-icon class.
.m-tabs__list Base style for div wrapping list of links for lazy-load tabs   .m-tabs .m-tabs--links > div  
.m-tabs__content Base style for section tabbed content Yes .m-tabs__heading + div  
.js-m-tab-open Style to enabled the section tab to be automatically opened on page load   .m-tabs__heading Should not be used in nested tabs.

Keyboard operations

TAB

Tabbing to an anchor should make the anchor clearly visually different so that the focus point on the page is obvious to the user.

SPACE or ENTER

With focus on an anchor, pressing SPACE or ENTER will open the link. If the link is internal to the page it will scroll the page otherwise it will load the new page.

Component releases

  • Added on: v3.0.0 (15/09/17)
  • Updated on: v5.9.0 (13/07/21)

Latest update:

  • updated: Section tabs can be controlled programatically to open a specified tab and optionally scroll to it.

Full version history

A full history of changes and enhancements detailing all minor and major updates to the component.

View full version history

Want something new in Framework, or to chat about an issue you're having with it?

Contact the team