Roots
Back

An Introduction To CSS Classes

What is a CSS class?

A class in CSS is made up of a selector - the name of the class, and a property: value pair;

selector { property: value; }
body {background-color: #000000; }

How to use CSS classes

You can write code for any HTML tag, like <img>, <p> or <body> as in the above example.

If you specify formatting for an HTML tag, the properties that you provide values for will override the default formatting for those properties, for that tag. For example, look at the default attributes for HTML headings. If you were to write CSS code like this;

h1 {font-size: 18px; }

it would override the existing font-size for <h1> tags, but not the font-weight or margin. Note that when you are creating a style for an HTML element you simply give the name of the tag, and wherever the tag appears in your code, it will have the given styling.