Carousels
Fantasized Draft, 28 March 2019Anchor Link
- This version:
- https://uga.dev/documents/fantasized-specs/html-carousel
- Editors:
- Hiroya Uga
- Issue Tracking:
- GitHub Issues
AbstractAnchor Link
This specification defines a mechanism for bringing standard accessibility to carousels (sometimes referred to as slider).
1. IntroductionAnchor Link
Carousel is a widget that has a lot of problems (mostly related to accessibility) in spite of high demand.
By standardizing the concept and interface of carousel widget as an element, we hope that issues such as accessibility and performance will be resolved.
2. ConceptsAnchor Link
3. APIAnchor Link
3.1. Related elementsAnchor Link
3.1.1. The carousel
elementAnchor Link
- Categories:
- Flow content.
- Embedded content.
- Interactive content.
- Palpable content.
- Labelable.
- Contexts in which this element can be used:
- Where flow content is expected.
- Content model:
- Flow content other than text and void elements.
- Tag omission in text/html:
- Neither tag is omissible
- Content attributes:
- Global attributes
autoplay
- Hint that the carousel can be slide automatically when the page is loaded.controls
- Show user agent controls.current
- Number the current index.direction
- Direction the slider.loop
- Whether to loop the slides.type
- Slide animation type of carousel.- Allowed ARIA role attribute values:
carousel
- Allowed ARIA state and property attributes:
- Global aria-* attributes
- Any
aria-*
attributes applicable to the allowed roles . - DOM interface:
interface HTMLCarouselElement : HTMLElement {
attribute boolean autoplay;
attribute boolean controls;
attribute unsigned long current;
attribute DOMString direction;
attribute boolean loop;
attribute DOMString type;
void play();void pause(); };
The carousel
element represents a carousel widget that can combine multiple pieces of content into a compact display.
The current
attribute represent initial current position. If the current
attribute is present, user agents must parse it as an integer, in order to determine the attribute’s value. The default value is 1.
The autoplay
attribute is a boolean attribute. When present, the user agent will automatically begin slide of the carousel as soon.
The autoplay
IDL attribute must reflect the content attribute of the same name.
The loop
attribute is a boolean attribute that, if specified, indicates that the slide of carousel element is to seek back to the start of the slide upon reaching the end.
The loop
IDL attribute must reflect the content attribute of the same name.
The controls
attribute is a boolean attribute that, if specified, it indicates that the author has not provided a scripted controller and would like the user agent to provide its own set of controls.
If the attribute is present, or if scripting is disabled for the media element, then the user agent should expose a user interface to the user. This user interface should include features the pager buttons (next, prev), begin button for autoplay, pause button, and dot-Indicator for toggle to arbitrary slide in the carousel. Other controls may also be made available.
Even when the attribute is absent, however, user agents may provide controls to use of the carousel (e.g., swipe, keyboard interface), but such features should not interfere with the page’s normal rendering. The user agent may implement this simply by exposing a user interface to the user as if the controls
attribute was present.
If the user agent exposes a user interface to the user by displaying controls over the carousel
element, then the user agent should suppress any user interaction events while the user agent is interacting with this interface. (For example, if the user clicks on a carousel's pager control, mousedown
events and so forth would not simultaneously be fired at elements on the page.)
Where possible (specifically, for toggling slide, and for toggling autoplay), user interface features exposed by the user agent must be implemented in terms of the DOM API described above, so that, e.g., all the same events fire.
The controls
IDL attribute must reflect the content attribute of the same name.
The direction
attribute controls the swipe direction of the carousel
. It is an enumerated attribute with the following keywords .
left
- Slide left (right is next content)right
- Slide right (left is next content)up
- Slide up (bottom is next content)down
- Slide down (top is next content)
The missing value default is the left
state.
The type
attribute switches the animation type when the carousel slides. It is an enumerated attribute with the following keywords .
slide
- Slide animation onlyfade
- Fade out then fade in (without slide animation)fadeslide
- Fade out then fade in with slide animationcrossdissolve
- Cross dissolvecrossdissolveslide
- Cross dissolve with slide animation
The missing value default is the slide
state.
Also, the title
attribute has special semantics on this element.
If possible, the carousel
needs a label (accessible name) by title
attribute or aria-label
attribute etc. If omitted, assistive technology is expected to simply speak this element as a "carousel".
All child elements of the carousel
element are interpreted as slides
. Browsers that do not support this element will simply looks like lined up the flow contents of the child elements.
Adjustment of the number of display uses CSS.
For example, the following example shows the carousel element being used to show 3 slide of 5 slide at once.
<style>
carousel::slide {
width: 33%;
}
</style>
<carousel>
<div>First slide</div>
<div>Second slide</div>
<div>Third slide</div>
<div>Forth slide</div>
<div>Fifth slide</div>
</carousel>
The following example shows the carousel element being used to show 1 to 3 slide of 5 slide at once.
This carousel has a controller displayed, it slide to the right, animation type is fadeslide and the initial current position is the second one. The carousel is autoplayed at the same time as the page is loaded, and the slide loops.
<style>
carousel::slide {
min-width: 200px;
max-width: 33%;
}
</style>
<carousel type="fadeslide" controls current="2" autoplay direction="right" loop>
<div>First slide</div>
<div>Second slide</div>
<div>Third slide</div>
<div>Forth slide</div>
<div>Fifth slide</div>
</carousel>
3.1.2. The ::slide
pseudo-elementAnchor Link
The ::slide
pseudo-element is produced based on the carousel
element's child elements.
The semantics of each slide inherit the semantics of the underlying flow content.
However, user agents are not actually interpreted the ::slide
pseudo-element itself. The accessibility and semantics information that the carousel
element exposed to the accessibility API causes such interpretation.
This pseudo-element selector can be used to style carousel slides.
For example, the width
property of the pseudo-element represents the width of one slide of the carousel.
If the width is 33.3333%, the carousel
element is expected to be drawn in 3 columns. If it is 70%, it is expected that one slide will be drawn in the center and 15% of the previous and next slides of the same width will be drawn on the left and right.
In addition, if the carousel
element has not loop
attribute, it is expected that the previous slide when the slide is not advancing and the next slide when the slide is advanced to end are not drawn.
carousel::slide {
width: 33%;
}
In addition, the slide animation of the carousel
element uses CSS Transitions. The author is able to adjust slide animation by overriding the relevant properties.
carousel::slide {
transition-duration: 0.2s;
transition-timing-function: ease-out;
}
However, if you override the transition-property
value specified by the user agent by default, the carousel will not animate when sliding. Conversely, if you want to disable animation for any reason, you can do so by specifying transition-property
as none
.
In browsers that support the carousel
elements, selectors such as carousel > div
and carousel > *
do not target slides in the carousel
elements.
carousel::slide {
/* for carousel supported browsers */
min-width: 200px;
max-width: 33%;
transition-duration: 0.2s;
transition-timing-function: ease-out;
}
carousel > * {
/* for carousel not supported browsers */
margin: 0 0 30px;
}
Note that CSS selectors for elements in slides do not need to use the ::slide
pseudo-element. It is more constructive not to use pseudo-element selectors.
<style>
carousel div > p {
/* ... */
}
carousel::slide > p {
/* The targets of this rule set are same previous one. */
/* ... */
}
</style>
<carousel>
<div><p>lorem ipsum...</p></div>
<div><p>lorem ipsum...</p></div>
<div><p>lorem ipsum...</p></div>
</carousel>
3.1.3. The ::pager-next
and ::pager-prev
pseudo-elementAnchor Link
3.1.4. The ::dot
pseudo-elementAnchor Link
3.1.5. The ::toggle
pseudo-elementAnchor Link
3.1.5. The ::container
, ::slide-track
, and other wrapper pseudo-elements for layoutAnchor Link
::container
::slide-track
::slide-wrapper
::dots-wrapper
::pagers-wrapper
Styling such as vertical center and horizontal center is often attempted. There is a pseudo-element that plays the role of wrapper for that, but it can also be ignored by display: contents;
.
<carousel>
<carousel::container>
<carousel::slide-wrapper>
<carousel::slide-track>
<casousel::slide>#contents</casousel::slide>
<casousel::slide>#contents</casousel::slide>
<casousel::slide>#contents</casousel::slide>
</carousel::slide-track>
<carousel::pagers-wrapper />
<carousel::pager-next />
<carousel::pager-prev />
<carousel::pagers-wrapper />
</carousel::slide-wrapper>
<carousel::dots-wrapper>
<carousel::dot />
<carousel::dot />
<carousel::dot />
<carousel::toggle />
</carousel::dots-wrapper>
</carousel::container>
</carousel>