Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p>This is a demo of making tabs panel.</p>
<p>
  <ol>
    <li><a href='https://codepen.io/makzan/pen/gbdONG' target='_top'>Step 1: Defining HTML.</a>
    <li><a href='https://codepen.io/makzan/pen/MYqYWR' target='_top'>Step 2: Coding JavaScript.</a>
    <li><strong>Step 3: Indicating active Tab.</strong>
    <li><a href='https://codepen.io/makzan/pen/JoaoKK'>Extra Step: Adding AIRA roles.</a>
  </ol>
</p>
<div class='tab-panel'> <!-- Our focus -->
  <div class='tabs'> <!-- Tab navigation -->
    <a href='#tab1'>Tab 1</a>
    <a href='#tab2'>Tab 2</a>
    <a href='#tab3'>Tab 3</a>
  </div>
  <!-- Starting of tab content -->
  <div id='tab1' class='tab-content'>
    <h2>Content of tab 1</h2>
    <p>Content of tab 1 goes here.</p>
    <p>More content for tab 1.</p>
    <p>We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. </p>
    <p>We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. </p>
  </div>
  <div id='tab2' class='tab-content'>
    <h2>Content of tab 2</h2>
    <p>Content of tab 2 goes here.</p>
    <p>More content for tab 2.</p>
    <p>We can also have image here. <br><img src='http://unsplash.it/300/300' alt='placeholder image'></p>
    <p>We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. </p>
  </div>
  
  <div id='tab3' class='tab-content'>
    <h2>Content of tab 3</h2>
    <p>Content of tab 3 goes here.</p>
    <p>More content for tab 3.</p>
    <p>We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. </p>
    <p>We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. We need a very long text here. So here we place some dummy text, very long dummy text. </p>
  </div>
  <!-- End of tab content -->
</div>

<hr>
<p><small>This is a demo by Makzan. Created for the <a href='https://gum.co/jquery101'>Introducing jQuery</a> course.</small></p>
              
            
!

CSS

              
                /* Active tab link style */
a:link.active,
.active {
  color: BLACK;
  font-weight: bold;
  text-decoration: none;
}

/* Non-tab-related styles */
body {
  padding: 50px;
  font-size: 16pt;
}

a:link,
a:visited {
  color: BLUE;
}
              
            
!

JS

              
                // hide all tabs by default.
$('.tab-content').hide();

// show the first tab.
$('.tab-content:first').show();

// indicate first tab is active.
$('.tabs > a').removeClass('active');
$('.tabs > a:first').addClass('active');

// when click on the tab link.
$('.tabs > a').click(function(){
  // get the href, which is #tab1, #tab2 or #tab3
  var href = $(this).attr('href');
  
  // hide all tabs.
  $('.tab-content').hide();
  
  // show only the target tab.
  $(href).show();
  
  // indicate target tab is active.
  $('.tabs > a').removeClass('active');
  $('.tabs > a[href=' + href + ']:first').addClass('active');
  
  // disable default browser behavior.
  return false;
});
              
            
!
999px

Console