Yogesh Chauhan's Blog

How to create a simple tab interaction using CSS?

in CSS on February 7, 2021

We want to create a simple tab view like this one:

Generally we add a link to point to a page but we can also add ‘#id‘ to point it to a specific element.

When we click on the link, browsers will try to focus on the element. At that time, we can adjust the style of the elements to create tab view.

To do that we are going to use the CSS ‘:target‘ selector.

CSS :target Selector

The element we link into a tags using ‘#id‘ to is the target element. So, we can use it to style the current active target element.

We’ll use CSS display property on that targeted element to create the tab interface.


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Flash of Invisible Text and Mitt Romney Web Font ProblemCSSDefault Values in SCSS (Sass)SCSSHow to set the permissions on all files and folders in Mac?MiscellaneousValues and Types Basics in JavaScriptJavaScriptA simple example on grid ‘auto-fill’ vs ‘auto-fit’CSSThe difference between Class declarations and Class expressions in JavaScriptJavaScriptHow to avoid element shift on border change while hovering in CSS?CSSHow to convert an HTML radio buttons into a toggle switch using CSS?CSSHow to use PHPMailer to send an Email via Gmail SMTP Server?PHPSafe Practice to add Links to cross-origin destinationUI/UXHow to update database configurations in WordPress?WordPressWhat are Identifiers in JavaScript?JavaScript