English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rule (RULES)

Comprehensive List of CSS Properties

CSS .class class selector

Complete CSS Selector Reference Manual

Online Example

Use class="content" to select and set the style of all elements:

<!DOCTYPE html>
<html>
<title>Basic Tutorial Website(oldtoolbag.com)</title>
<head>
<style>
.content
{
background-color:yellow;
}
</style>
</head>
<body>
<h1>Welcome to my homepage</h1>
<div class="content">
<p>My name is Tutu.</p>
<p>I live in Canada.</p>
</div>
<p>My best friend is Lili.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

 .classA selector specifies the style for all elements of a class.

Browser Compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support it.classSelector

Online Example

Apply the style using class="myhome" to all <p> elements:

<!DOCTYPE html>
<html>
<title>Basic Tutorial Website(oldtoolbag.com)</title>
<head>
<style>
p.myhome
{ 
background:red;
}
</style>
</head>
<body>
<p>My name is Tutu.</p>
<p class="myhome">I live in Canada.</p>
<p>My name is Tutu.</p>
<p class="myhome">I live in Canada.</p>
</body>
</html>
Test to see ‹/›
Complete CSS Selector Reference Manual