w1coding.comAll tutorials

CSS Z Index

CSS lessons
  1. Environment Setup
  2. Introduction
  3. Tdisplay
  4. Basics
  5. Editors
  6. Syntax
  7. Colors
  8. Background
  9. Borders
  10. Margins
  11. Padding
  12. Width And Height
  13. Outline
  14. Texts
  15. Fonts
  16. Icons
  17. Links
  18. Lists
  19. Display
  20. Tables
  21. Max And With
  22. Positon
  23. Z Index
  24. Dropdown
  25. Overflow
  26. Float
  27. Navigation
  28. Image Sprites

What is a Class?

A class is an attribute that you can assign to HTML elements to group them together. Classes allow you to apply the same styles to multiple elements and can also be used for JavaScript manipulation.

How to Use Classes

You can define a class in your HTML by adding the class attribute to an element:

<div class="example">This is a div with a class.</div>

In your CSS, you can style the class by using a dot (.) followed by the class name:

.example { background-color: lightblue; }

Examples of Classes

Example 1: Multiple Elements with the Same Class

Here are multiple paragraphs styled with the same class:

This paragraph is highlighted.

This paragraph is also highlighted.

And this one is highlighted too!

Example 2: Centered Text

This text is centered using a class.

This text is not centered.

Example 3: Combining Classes

This paragraph is both highlighted and centered!