Documentation Index Fetch the complete documentation index at: https://mintlify.com/ganlanyuan/tiny-slider/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Tiny Slider provides a flexible styling system with both compiled CSS and SCSS source files. This guide covers CSS inclusion, customization options, and how to style controls, navigation, and other components.
CSS File Inclusion
CDN (Quickest)
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/tiny-slider.css" >
IE8 Polyfills
If you need to support Internet Explorer 8:
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/tiny-slider.css" >
<!--[if (lt IE 9)]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/min/tiny-slider.helper.ie8.js"></script>
<![endif]-->
Local Installation
Then import in your project:
import 'tiny-slider/dist/tiny-slider.css' ;
Core CSS Classes
Container Classes
Tiny Slider automatically adds these classes to the slider container:
// Outer wrapper
.tns-outer {
padding : 0 !important ;
}
// Main slider container
.tns-slider {
transition : all 0 s ;
}
// Mode classes
.tns-carousel { /* Carousel mode */ }
.tns-gallery { /* Gallery mode */ }
// Direction classes
.tns-horizontal { /* Horizontal slider */ }
.tns-vertical { /* Vertical slider */ }
// Layout classes
.tns-subpixel { /* Uses inline-block layout */ }
.tns-no-subpixel { /* Uses float layout */ }
.tns-calc { /* Browser supports calc() */ }
.tns-no-calc { /* No calc() support */ }
.tns-autowidth { /* Auto width mode */ }
Slide Classes
// Base slide item
.tns-item {
box-sizing : border-box ;
}
// Active visible slide
.tns-slide-active { }
// Cloned slides (for loop)
.tns-slide-cloned { }
// Gallery animation classes
.tns-fadeIn {
opacity : 1 ;
filter : alpha ( opacity =100 );
z-index : 0 ;
}
.tns-fadeOut {
opacity : 0 ;
filter : alpha ( opacity =0 );
z-index : -1 ;
}
.tns-normal {
opacity : 0 ;
filter : alpha ( opacity =0 );
z-index : -1 ;
}
// Transitioning slide
.tns-moving {
transition : all 0.25 s ;
}
Utility Classes
// Overflow hidden wrapper
.tns-ovh {
overflow : hidden ;
}
// Auto height transition
.tns-ah {
transition : height 0 s ;
}
// Hidden for screen readers
.tns-visually-hidden {
position : absolute ;
left : -10000 em ;
}
// Transparent (hidden)
.tns-transparent {
opacity : 0 ;
visibility : hidden ;
}
Customizing Appearance
Basic Slider Styling
/* Container styling */
.my-slider {
max-width : 1200 px ;
margin : 0 auto ;
}
/* Individual slides */
.my-slider .tns-item {
padding : 10 px ;
}
.my-slider .tns-item img {
width : 100 % ;
height : auto ;
display : block ;
}
Slide Transitions
/* Custom transition speed */
.tns-slider {
transition : transform 0.5 s ease-in-out ;
}
/* Slide items in carousel mode */
.tns-carousel .tns-item {
transition : opacity 0.3 s ;
}
/* Gallery mode custom animations */
.tns-gallery > .tns-item {
transition : transform 0 s , opacity 0 s ;
}
.tns-gallery > .tns-moving {
transition : all 0.4 s cubic-bezier ( 0.4 , 0 , 0.2 , 1 );
}
SCSS Variables
The source SCSS file (tiny-slider.scss) includes variables for browser capability detection:
// Browser detection helper dimensions
$width : 310 px ;
$height : 10 px ;
$count : 70 ;
$perpage : 3 ;
.tns-t {
& -subp2 {
margin : 0 auto ;
width : $width ;
position : relative ;
height : $height ;
overflow : hidden ;
}
& -ct {
width : ( 100 % * $count / $perpage );
width : calc ( 100 % * #{$count} / #{$perpage} );
position : absolute ;
right : 0 ;
> div {
width : ( 100 % / $count );
width : calc ( 100 % / #{$count} );
height : $height ;
float : left ;
}
}
}
These variables are used internally for feature detection and typically don’t need modification.
Custom Controls Styling
Default Controls
/* Controls container */
.tns-controls {
text-align : center ;
margin : 20 px 0 ;
}
/* Control buttons */
.tns-controls button {
padding : 10 px 20 px ;
margin : 0 5 px ;
background : #333 ;
color : white ;
border : none ;
border-radius : 4 px ;
cursor : pointer ;
transition : background 0.3 s ;
}
.tns-controls button :hover {
background : #555 ;
}
.tns-controls button :disabled {
background : #ccc ;
cursor : not-allowed ;
opacity : 0.5 ;
}
/* Data attribute selectors */
[ data-controls = "prev" ] {
/* Previous button specific styles */
}
[ data-controls = "next" ] {
/* Next button specific styles */
}
Custom Control Markup
<!-- Custom controls container -->
< div class = "custom-controls" >
< button class = "prev-btn" > Previous </ button >
< button class = "next-btn" > Next </ button >
</ div >
< div class = "my-slider" >
<!-- slides -->
</ div >
var slider = tns ({
container: '.my-slider' ,
prevButton: '.prev-btn' ,
nextButton: '.next-btn'
});
.custom-controls {
display : flex ;
justify-content : space-between ;
margin-bottom : 20 px ;
}
.custom-controls button {
padding : 12 px 24 px ;
background : linear-gradient ( 135 deg , #667eea 0 % , #764ba2 100 % );
color : white ;
border : none ;
border-radius : 25 px ;
font-weight : 600 ;
cursor : pointer ;
transition : transform 0.2 s , box-shadow 0.2 s ;
}
.custom-controls button :hover {
transform : translateY ( -2 px );
box-shadow : 0 4 px 12 px rgba ( 0 , 0 , 0 , 0.15 );
}
Custom Navigation Styling
Default Nav Dots
/* Nav container */
.tns-nav {
text-align : center ;
margin : 20 px 0 ;
}
/* Individual dots */
.tns-nav button {
width : 12 px ;
height : 12 px ;
padding : 0 ;
margin : 0 5 px ;
border-radius : 50 % ;
background : #ddd ;
border : none ;
cursor : pointer ;
transition : all 0.3 s ;
}
.tns-nav button :hover {
background : #999 ;
transform : scale ( 1.2 );
}
/* Active dot */
.tns-nav .tns-nav-active {
background : #333 ;
transform : scale ( 1.3 );
}
Thumbnail Navigation
/* Thumbnail nav */
.tns-nav {
display : flex ;
justify-content : center ;
gap : 10 px ;
margin : 20 px 0 ;
}
.tns-nav button {
width : 80 px ;
height : 60 px ;
padding : 0 ;
border : 2 px solid transparent ;
border-radius : 4 px ;
overflow : hidden ;
cursor : pointer ;
transition : all 0.3 s ;
background-size : cover ;
background-position : center ;
}
.tns-nav button :hover {
border-color : #999 ;
}
.tns-nav .tns-nav-active {
border-color : #333 ;
box-shadow : 0 4 px 8 px rgba ( 0 , 0 , 0 , 0.2 );
}
var slider = tns ({
container: '.my-slider' ,
navAsThumbnails: true
});
Custom Nav Container
< div class = "my-slider" >
<!-- slides -->
</ div >
< div class = "custom-nav" >
< button data-nav = "0" > Slide 1 </ button >
< button data-nav = "1" > Slide 2 </ button >
< button data-nav = "2" > Slide 3 </ button >
</ div >
var slider = tns ({
container: '.my-slider' ,
navContainer: '.custom-nav'
});
/* Autoplay button */
[ data-action ] {
padding : 10 px 20 px ;
background : #4CAF50 ;
color : white ;
border : none ;
border-radius : 4 px ;
cursor : pointer ;
font-weight : 600 ;
transition : background 0.3 s ;
}
[ data-action ] :hover {
background : #45a049 ;
}
/* Different states */
[ data-action = "stop" ] {
background : #f44336 ;
}
[ data-action = "start" ] {
background : #4CAF50 ;
}
Lazyload Styling
/* Lazyloading images */
.tns-lazy-img {
transition : opacity 0.6 s ;
opacity : 0.6 ;
}
.tns-lazy-img.tns-complete {
opacity : 1 ;
}
/* Loading state */
.tns-lazy-img.loading {
background : linear-gradient (
90 deg ,
#f0f0f0 25 % ,
#e0e0e0 50 % ,
#f0f0f0 75 %
);
background-size : 200 % 100 % ;
animation : loading 1.5 s infinite ;
}
@keyframes loading {
0% { background-position : 200 % 0 ; }
100% { background-position : -200 % 0 ; }
}
/* Failed state */
.tns-lazy-img.failed {
opacity : 0.3 ;
position : relative ;
}
.tns-lazy-img.failed::after {
content : '✕' ;
position : absolute ;
top : 50 % ;
left : 50 % ;
transform : translate ( -50 % , -50 % );
font-size : 2 rem ;
color : #f44336 ;
}
Live Region Styling
/* Accessible live region (typically visually hidden) */
.tns-liveregion {
position : absolute ;
left : -10000 em ;
/* If you want to display it for debugging: */
/* position: relative; */
/* left: 0; */
/* padding: 10px; */
/* background: #f0f0f0; */
}
Dark Mode Considerations
/* Automatic dark mode with prefers-color-scheme */
@media (prefers-color-scheme: dark) {
.tns-outer {
background : #1a1a1a ;
}
.tns-controls button {
background : #f0f0f0 ;
color : #1a1a1a ;
}
.tns-controls button :hover {
background : #ffffff ;
}
.tns-controls button :disabled {
background : #444 ;
color : #888 ;
}
.tns-nav button {
background : #444 ;
}
.tns-nav .tns-nav-active {
background : #f0f0f0 ;
}
}
/* Manual dark mode with class */
.dark-mode .tns-outer {
background : #1a1a1a ;
color : #f0f0f0 ;
}
.dark-mode .tns-controls button {
background : #2a2a2a ;
color : #f0f0f0 ;
border : 1 px solid #444 ;
}
Responsive Styling
/* Mobile-first approach */
.my-slider .tns-item {
padding : 10 px ;
}
.tns-controls button {
padding : 8 px 16 px ;
font-size : 14 px ;
}
/* Tablet */
@media ( min-width : 640 px ) {
.my-slider .tns-item {
padding : 15 px ;
}
.tns-controls button {
padding : 10 px 20 px ;
font-size : 16 px ;
}
}
/* Desktop */
@media ( min-width : 1024 px ) {
.my-slider .tns-item {
padding : 20 px ;
}
.tns-controls button {
padding : 12 px 24 px ;
font-size : 16 px ;
}
}
Complete Example
Full Styled Slider Example
<! DOCTYPE html >
< html >
< head >
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.4/tiny-slider.css" >
< style >
.slider-container {
max-width : 1200 px ;
margin : 50 px auto ;
padding : 0 20 px ;
}
.my-slider .tns-item {
padding : 10 px ;
}
.my-slider img {
width : 100 % ;
height : 400 px ;
object-fit : cover ;
border-radius : 8 px ;
}
.tns-controls {
text-align : center ;
margin-top : 30 px ;
}
.tns-controls button {
padding : 12 px 30 px ;
margin : 0 10 px ;
background : linear-gradient ( 135 deg , #667eea 0 % , #764ba2 100 % );
color : white ;
border : none ;
border-radius : 25 px ;
font-weight : 600 ;
cursor : pointer ;
transition : all 0.3 s ;
}
.tns-controls button :hover:not ( :disabled ) {
transform : translateY ( -2 px );
box-shadow : 0 6 px 20 px rgba ( 102 , 126 , 234 , 0.4 );
}
.tns-controls button :disabled {
opacity : 0.5 ;
cursor : not-allowed ;
}
.tns-nav {
text-align : center ;
margin-top : 20 px ;
}
.tns-nav button {
width : 12 px ;
height : 12 px ;
padding : 0 ;
margin : 0 6 px ;
border-radius : 50 % ;
background : #ddd ;
border : none ;
cursor : pointer ;
transition : all 0.3 s ;
}
.tns-nav .tns-nav-active {
background : #667eea ;
transform : scale ( 1.4 );
}
</ style >
</ head >
< body >
< div class = "slider-container" >
< div class = "my-slider" >
< div >< img src = "slide1.jpg" alt = "Slide 1" ></ div >
< div >< img src = "slide2.jpg" alt = "Slide 2" ></ div >
< div >< img src = "slide3.jpg" alt = "Slide 3" ></ div >
</ div >
</ div >
< script src = "https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.2/min/tiny-slider.js" ></ script >
< script >
var slider = tns ({
container: '.my-slider' ,
items: 1 ,
slideBy: 'page' ,
autoplay: true ,
autoplayButtonOutput: false ,
speed: 400 ,
responsive: {
640 : {
items: 2 ,
gutter: 20
},
900 : {
items: 3 ,
gutter: 20
}
}
});
</ script >
</ body >
</ html >
Best Practices
Use CSS Specificity Wisely
Target Tiny Slider classes with appropriate specificity to avoid conflicts: /* Good */
.my-slider .tns-item { }
/* Avoid overly specific */
.wrapper .container .my-slider .tns-outer .tns-item { }
Respect Core Functionality
Don’t override critical positioning and transform properties that Tiny Slider uses internally.
Test Across Browsers
Ensure your custom styles work with the various layout modes (subpixel, no-subpixel, calc, no-calc).
Consider Accessibility
Maintain sufficient color contrast and ensure focus states are visible.
Next Steps
Configuration Configure slider behavior
Methods Control slider programmatically
Accessibility Make your slider accessible
Examples View styling examples