The elements of a web page can be positioned in three dimensions. “Layers” can be positioned partially or completely above or below other layers.

In this tutorial:

  1. Syntax
  2. Codepen

Required knowledge:

Syntax

Simply apply the z-index attribute with an integer as the value. An element with a z-index of 2 is above an element with a z-index of 1.

z-index: integer;

z-index values can be negative integers.

Codepen

Play with the z-index values in the Codepen below:

See the Pen Stacking up with CSS by David Fox (@foxbeefly) on CodePen.


References:

  1. W3Schools.com (No date) CSS z-index property. Available at: https://www.w3schools.com/cssref/pr_pos_z-index.php (Accessed: 31 August 2023).
  2. W3Schools.com (no date) CSS layout – the position property. Available at: https://www.w3schools.com/css/css_positioning.asp (Accessed: 31 August 2023).

By @MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher and Young Engineers instructor. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.