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

Carousel


Design and usage

  • A maximum of four cards can be placed alongside each other in a desktop view, two at tablet view and one at mobile view.
  • A maximum of five frames (groups of cards, eg. in a desktop view the max would be five groups of four cards each) should be used.
  • Dots underneath the carousel indicate the user's location within the carousel and may also be used to navigate directly to an alternative frame. Direction controls placed to the side of the cards also allow users to skip to the next view. When users reach the first or last view, no arrow is present to indicate they can't progress the view further in that direction.
  • Cards may include images and links as appropriate.
  • At tablet and mobile viewports, where possible a small section of the adjoining cards being in view gives a further indicator that there is more content to navigate to (see examples below).
  • By default only the first four cards will be shown when JavaScript is not available. However, if for regulatory reasons all cards need to be displayed for non-js (ie. need to display all policy documents) the option is available.
  • Can be used for both editorial (standard links) and navigation (whole card as a link) cards.
  • Carousels must not be used where users need to view the available information simultaneously - they can be overlooked by users, and some content will be hidden from first view.
  • Card carousels should not auto-forward.

Examples

Interactive example

Code example

Link cards

<div class="l-columns o-carousel [ Modifier ]" data-slides="..." data-module="o-carousel">
	<div class="l-columns__column m-card m-card--link [ Modifier ]" href="...">
		...
	</div>
	...
</div>

Editorial cards

<div class="l-columns o-carousel [ Modifier ]" data-module="o-carousel">
	<div class="l-columns__column m-card [ Modifier ]">
		...
	</div>
	...
</div>

Show all cards when JavaScript is not available

This variant is for showing cards that contain content/links that must able to be viewed to adhere to regulatory requirements.

Development and test

Notes for developers

Built to be used in conjunction with Cards. Examples of how these can be used within a page will be available shortly.

All cards within a single carousel must have equal widths but the number of cards shown at any one time at the different widths can be adjusted to match the layout when JavaScript is now available. This can be achieved by including the data attribute data-slides along side the data-module attribute. The value should be formatted as and array with the number of cards required for display at small, medium then large screen. For example if 1 card was required for small, 2 at medium and 3 at large the code would be:

<div class="l-columns l-columns--2-medium l-columns--3-large o-carousel" data-module="o-carousel" data-slides="[1,2,3]">

To disable the carousel at a particular breakpoint set the number of cards to 0. For example to have a carousel only at mobile data-slides should be set too [1,0,0].

Changing locale settings

Default text for the navigation controls can be changed for a particular locale.

en: {
	oCarousel : {
		previousPageLong : 'Previous, {x} of {y}',
		previousPage : 'Previous',
		page : '{x} of {y}',
		nextPageLong : 'Next, {x} of {y}',
		nextPage : 'Next',
	},
},

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

Controling the carousel programatically

Carousels can be controlled programatically to move forward and backwards by a single slide or move to a particular slide by referencing the particular card that needs to be navigated to. The following methods are available for use:

Method Description
oCarousel.nextSlide() Moves the carousel to the next slide (group of cards)
oCarousel.previousSlide() Moves the carousel to the prevous slide (group of cards)
oCarousel.gotoSlide( '#uniqueCardId' )

Moves the carousel to the slide that contains the card with the unique selector provided.

By providing the selector for a card that is required to be displayed ensures correct navigation to the card at all screen sizes.

oCarousel.gotoSlide( 3 )

Moves the carousel to the slide that contains the card with the index provided for example index 1 would move to the first card within the carousel, if index 5 was provided and 4 cards per slide are displayed at a time the carousel will move to the second slide to display card 5.

By providing the index of the card that is required to be displayed ensures correct navigation to the card at all screen sizes.

For example:

document.addEventListener( 'frameworkready', function () {
	FRAMEWORK.require([ 'blocks/o-carousel' ], function ( oCarouselModule ) {
		var carouselEl = document.querySelector( '#carouselId' ),
			carouselInstance = oCarouselModule.initInstance( carouselEl );		carouselInstance.gotoSlide( '#uniqueCardId' );
	});
});

Notes for testers

  • Card carousel will only display when the number of cards exceeds the maximum single line width at each breakpoint, ie.:

    • over 60em: four single cards;
    • over 35em: two single cards;
    • less than 35em: one single card.
  • If no JavaScript is present, by default only the first of four single cards will display; all other cards will be hidden.
  • Pagination is hidden below the 60em breakpoint.
  • 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.
  • Ensure that text within links is descriptive of what or where the link is going. Additional text descriptive text can be hidden visually from the user to aid in make the link understandable especially if there area number of links such as "Find out more" on the page which go to different locations.

Classes overview

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

Class Outcome Required Applied to Comments
.o-carousel Base style for carousel Yes .l-columns  
.o-carousel--all Variant style to show all cards when JavaScript is not available   .o-carousel Only use this variant to adhere to regulatory requirements

Keyboard operations

TAB

Tabbing to an anchor should make the link 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 relevant page.

Component releases

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

Latest update:

  • updated: Carousels can now be controlled programatically to move forward and backwards by a single slide or move to a particular slide.

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