CSS: Tabbed Menu

By Xah Lee. Date: . Last updated: .

This page shows you how to implement Tabbed Menu using CSS.

Click on the tab on top of this page. You can see that pages get switched and the corresponding tab gets highlighted. Here's how this is done in pure CSS.

Let's say you want a tab menu for 3 pages: A, B, C.

Put this into the top of page A:

<ul id="pageA" class="tabs">
<li id="a"><a href="a.html">Tab A</a></li>
<li id="b"><a href="b.html">Tab B</a></li>
<li id="c"><a href="c.html">Tab C</a></li>

Also, put it into page B and C, but use id="pageB" and id="pageC".

Then, all you have to do is use the style sheet to control how your tab should look. Notice that in the above code there's id="pageA". So, in your style sheet, you specify a appearance for tag that match “pageA”. Like this:

#pageA #a {background-color:red}
#pageA #b {background-color:silver}
#pageA #c {background-color:silver}

#pageB #a {background-color:silver}
#pageB #b {background-color:red}
#pageB #c {background-color:silver}

#pageC #a {background-color:silver}
#pageC #b {background-color:silver}
#pageC #c {background-color:red}

Here's the complete CSS code for all the pages:

 border-bottom:6px solid red;
 width: 70vw;

ul.tabs li

ul.tabs a:link {text-decoration:none; color:black}
ul.tabs a:visited {text-decoration:none; color:black}

#pageA #a {background-color:red;
 padding-bottom: 7px;
#pageA #b {background-color:silver}
#pageA #c {background-color:silver}

#pageB #a {background-color:silver}
#pageB #b {background-color:red;
 padding-bottom: 7px;
#pageB #c {background-color:silver}

#pageC #a {background-color:silver}
#pageC #b {background-color:silver}
#pageC #c {background-color:red;
 padding-bottom: 7px;

Note that we also draw a red line under the tabs. This is done by border-bottom. This line should have the same color as the active tab.

We set the li to not show its normal bullets for list items. This is done by list-style:none

We set li to have display:inline, so it flows from left to right. [see CSS: Flowing List]

We make each li to have background color so it looks like a solid tab.

Finally, we make the top corners of the tab round. This is done by border radius. [see CSS: Round Corners]

Note: it's also possible to implement tabbed menu using JavaScript. But usually that's not a good solution. Because using CSS is much simpler and efficient.

[see Tabbed Menu with Pure JavaScript]

CSS Basics

  1. Basics
  2. Tag Matching Tutorial
  3. Selector Syntax
  4. Units


  1. Color Syntax
  2. Color Names
  3. Opacity
  4. Linear Gradient
  5. Radial Gradient


  1. font-family
  2. Standard Web Fonts
  3. font-size
  4. Meaning of Font Size
  5. Font Weight
  6. Chinese Font Names

Box Model

  1. Border
  2. Outline
  3. Margin vs Padding
  4. Box Sizing


  1. Layout Tutorial
  2. Display Property
  3. Position: static, relative, fixed, absolute
  4. Pure CSS Table
  5. Tabbed Menu
  6. 3 Columns Page Layout
  7. Multi-Column Layout for Text Flow
  8. Fix Element to Window
  9. Centering
  10. Flowing List
  11. z-index
  12. Text Over Image
  13. Text Flow Around Image
  14. OverFlow, Scrollbar


  1. 2D Transform
  2. Transition
  3. Animation

Line Wrap, Justification

  1. Line Wrap
  2. Text Alignment, Justification
  3. Match first-letter and first-line
  4. “:before”, “:after”
  5. Text Decoration: Underline, Overline, Line-Through
  6. Letter Spacing, Word Spacing

Box Decoration

  1. Box Shadow
  2. Text Shadow
  3. Round Corners
  4. Background Image
  5. Image Rollover


  1. Computed Style
  2. Pseudo Class vs Pseudo Element
  3. Media Query
  4. Variable
  5. calc
  6. Reset
  7. user-select
  8. Data URI Scheme
  9. protocol-relative URL
  10. Default Unit
  11. Declaring Character Set in CSS File
  12. Jargons Explained: Tag, Element, Node, Object, Attribute, Property, Method
  13. Display Table on Small Screen
  14. Fixed Aspect Ratio
  15. Add Icon to Links
  16. Progress Bar Example

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials