Skip to content
Related Articles

Related Articles

Foundation CSS Switch

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Jun, 2022
View Discussion
Improve Article
Save Article

Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is built on Saas-like bootstrap. It is more sophisticated, flexible, and easily customizable. It also comes with CLI, so it’s easy to use it with module bundlers. It offers the Fastclick.js tool for faster rendering on mobile devices.

Switch in general gives the user an option to select one of the two possibilities present. 

In this article, we will discuss all the switch properties used in Foundation CSS.

Foundation CSS Switch Classes:

  • Basics: This uses a switch, switch-input, switch-paddle, and show-for-sr classes to create basic switches. 
  • Disabled: This uses a disabled attribute that fixes a switch into a fixed or static position. This can be accomplished by setting this on the input control having the switch-input class.
  • Radio Switch: This uses the type=”radio” attribute that indicates the input type of the element with the switch-input class.
  • Sizing Classes: This uses classes like tiny, small, and large to provide different sizes to the buttons.
  • Inner Labels: This uses switch-active and switch-inactive classes to indicate the text to be enabled and disabled respectively when the switch is toggled. 

Syntax:

<div class="switch">
    <input class="switch-input" id="xy" 
        type="checkbox" name="xy">
    <label class="switch-paddle" for="xy">
        <span class="show-for-sr">...</span>
    </label>
</div>

Example 1: Below example illustrates the basic switches created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Foundation CSS Switch</title>
        <!-- Compressed CSS -->
        <link rel="stylesheet"
            href=
        <link rel="stylesheet"
            href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css"/>
  
        <!-- Compressed JavaScript -->
        <script src=
        </script>
        <script src=
        </script>
    </head>
    <body>
        <center>
            <h1 style="color:green;">GeeksforGeeks</h1>
            <strong>Foundation CSS Switch</strong>
            <br/><br/>
            <div class="switch">
                <input class="switch-input"
                    id="exampleSwitch"
                    type="checkbox"
                    name="exampleSwitch">
                <label class="switch-paddle"
                    for="exampleSwitch">
                <span class="show-for-sr">GeeksforGeeks</span>
                </label>
            </div>
        </center>
        <script>
            $(document).foundation();
        </script>
    </body>
</html>


Output:

Foundation CSS Switch Basics

Example 2: Below example illustrates the disabled switches created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Foundation CSS Switch Disabled</title>
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css" />
    <!-- Compressed JavaScript -->
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <center>
      <h1 style="color: green;">GeeksforGeeks</h1>
      <strong>Foundation CSS Switch Disabled</strong>
    </center>
    
    <div style="margin: 3% 42%;">
        <p>CheckedDisabledSwitch</p>
        <div class="switch">
          <input class="switch-input" disabled checked="checked"
          id="exampleCheckedDisabledSwitch" type="checkbox"
            name="exampleCheckedDisabledSwitch">
          <label class="switch-paddle" for="exampleCheckedDisabledSwitch">
            <span class="show-for-sr">Can't Touch This Checked</span>
          </label>
        </div>
          
        <p>UncheckedDisabledSwitch</p>
        <div class="switch">
          <input class="switch-input" disabled
            id="exampleUncheckedDisabledSwitch"
            type="checkbox"
            name="exampleUncheckedDisabledSwitch">
          <label class="switch-paddle"
          for="exampleUncheckedDisabledSwitch">
            <span class="show-for-sr">
              Can't Touch This Unchecked
            </span>
          </label>
        </div>
    </div>
    
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

Foundation CSS Disabled Switch

Example 3: Below example illustrates the Radio switches created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Foundation CSS Radio Switch</title>
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css" />
    <!-- Compressed JavaScript -->
    <script src=
</script>
    <script src=
</script>
</head>
  
<body>
    <center>
        <h1 style="color: green;">GeeksforGeeks</h1>
        <strong>Foundation CSS Radio Switch</strong>
    </center>
    <div style="margin: 5% 45%;">
        <div class="switch">
            <input class="switch-input" id="exampleRadioSwitch1"
            type="radio" checked name="testGroup">
            <label class="switch-paddle" for="exampleRadioSwitch1">
                <span class="show-for-sr">Radio Switch</span>
            </label>
        </div>
        <div class="switch">
            <input class="switch-input" id="exampleRadioSwitch2"
            type="radio" checked name="testGroup">
            <label class="switch-paddle" for="exampleRadioSwitch2">
                <span class="show-for-sr">Radio Switch</span>
            </label>
        </div>
        <div class="switch">
            <input class="switch-input" id="exampleRadioSwitch3"
            type="radio" checked name="testGroup">
            <label class="switch-paddle" for="exampleRadioSwitch3">
                <span class="show-for-sr">Radio Switch</span>
            </label>
        </div>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

Foundation CSS Radio Switch

Example 4: Below example illustrates the switches created using sizing classes in Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Foundation CSS Switch Sizing Classes</title>
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    />
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css"
    />
    <!-- Compressed JavaScript -->
    <script src=
</script>
    <script src=
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <strong>Foundation CSS Switch Sizing Classes</strong>
    </center>
    <div style="margin:5% 45%">
        <span>Tiny Switch</span>
        <div class="switch tiny">
            <input class="switch-input" id="tinySwitch" type="checkbox"
                   name="exampleSwitch1"
            />
            <label class="switch-paddle" for="tinySwitch">
                <span class="show-for-sr">Tiny Sandwiches Enabled</span>
            </label>
        </div>
        <span>Small Switch</span>
        <div class="switch small">
            <input class="switch-input" id="smallSwitch" type="checkbox"
                  name="exampleSwitch2"
            />
            <label class="switch-paddle" for="smallSwitch">
                <span class="show-for-sr">Small Portions Only</span>
            </label>
        </div>
        <span>Large Switch</span>
        <div class="switch large">
            <input class="switch-input" id="largeSwitch" type="checkbox"
                  name="exampleSwitch3"
            />
            <label class="switch-paddle" for="largeSwitch">
               <span class="show-for-sr">Show Large Elephants</span>
            </label>
        </div>
    </div>
  
    <script>
        $(document).foundation();
    </script>
</body>
    
</html>


Output:

Foundation CSS Sizing Switch

Example 5: Below example illustrates the Inner Labels switches created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Foundation CSS InnerLabels Switch</title>
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css" />
    <!-- Compressed JavaScript -->
    <script src=
</script>
    <script src=
</script>
</head>
  
<body>
    <center>
        <h1 style="color: green;">GeeksforGeeks</h1>
        <strong>Foundation CSS InnerLabels Switch</strong>        
        <p>Select Your Age below</p>
    </center>
  
    <div style="margin: 5% 40%;">
        <span>Age below 19</span>
        <div class="switch large">
            <input class="switch-input" id="yes-no1"
            type="radio" name="exampleSwitch">
            <label class="switch-paddle" for="yes-no1">
                <span class="show-for-sr">Do you like me?</span>
                <span class="switch-active" aria-hidden="true">Yes</span>
                <span class="switch-inactive" aria-hidden="true">No</span>
            </label>
        </div>
        <span>Age between 20-45</span>
        <div class="switch large">
            <input class="switch-input" id="yes-no2"
            type="radio" name="exampleSwitch">
            <label class="switch-paddle" for="yes-no2">
                <span class="show-for-sr">Do you like me?</span>
                <span class="switch-active" aria-hidden="true">Yes</span>
                <span class="switch-inactive" aria-hidden="true">No</span>
            </label>
        </div>
        <span>Age above 45</span>
        <div class="switch large">
            <input class="switch-input" id="yes-no3"
            type="radio" name="exampleSwitch">
            <label class="switch-paddle" for="yes-no3">
                <span class="show-for-sr">Do you like me?</span>
                <span class="switch-active" aria-hidden="true">Yes</span>
                <span class="switch-inactive" aria-hidden="true">No</span>
            </label>
        </div>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
</html>


Output:
 

Foundation CSS Inner Labels Switch

Reference: https://get.foundation/sites/docs/switch.html


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!