Cara menggunakan css :has

Are you looking for a way to stylize HTML elements without hassle? Chances are, you will have to use CSS classes. In this article, you will find out what exactly are classes in CSS and how to use them effectively.

Cara menggunakan css :has

What Is a CSS Class?

CSS syntax contains a selector, and a class is exactly that. It is needed to stylize HTML elements – including changing colors, fonts, or the size of a text.

If you want to use a class, use a full stop (.) followed by the class name in a style block. Next, use a bracket called a declaration block that contains the property to stylize the element, such as text color or text size.

Let’s take an example, here’s how it looks if you want to change the text color to green:

CSS Classes will help you stylize HTML elements quickly. Moreover, you can avoid repeating the same code for each HTML element that uses the same styling. Hence, the amount of CSS code to use is reduced – which makes it more readable and easier to debug.

On another note, you can also use an ID selector to stylize HTML elements. However, it’s only able to change one HTML element, whereas a class selector can stylize more than one element.

How to Use a CSS Class to Style an Element?

Ready to use CSS classes? The examples below will help you get a real grasp of the concept. Let’s start by creating classes using style tags:



Let’s break it down and see what each part represents: