Trusted answers to developer questions

How to create tabs in HTML

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

All web applications have some method of allowing the user to navigate to different sections of the application. Tabs are commonly used to achieve this.

svg viewer

Code

The following code snippet uses HTML, JavaScript, and CSS to create tabs:

Explanation

  • Lines 6-10 create the three buttons that act as tabs. All of them have an onClick handler associated with them.
  • Lines 12-22 create the content to be displayed once the tabs are clicked.
  • Lines 24-44 contain the JavaScript code for the clickHandle function, which is invoked when a tab button is clicked. The function sets the clicked tab to be ​active and displays its corresponding content.

RELATED TAGS

tabs
html
css
javascript
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?