codescracker


html

HTML Classes



« Previous Tutorial Next Tutorial »


Class in HTML used to define a class to an HTML element and style that class of element using CSS.

Classing HTML elements, makes it possible to define CSS styles for particular classes of elements.

Equal styles for equal classes, or different styles for different classes.

HTML Class Example

Here is an example of class in HTML.

<!DOCTYPE html>
<html>
<head>
	<title>HTML Class Example</title>
	<style>
		.myclass{background-color:red; color:white; padding:20px;}
	</style>
</head>
<body>

<p>This is out of class named myclass.</p>
<div class="myclass">
	<h2>Class in HTML</h2>
	<p>This is in class named myclass. In this tutorial, you will learn all about class in HTML
	with examples. You can define a class to an HTML element to style all the part of that element
	using the class name.</p>
</div> 

</body>
</html>

Here is the sample output produced by the above HTML class example code:

html class

HTML Class Block

The HTML <div> element is a block level element. It can be used as a container for other HTML elements.

Classing <div< elements, makes it possible to define equal styles for equal <div> elements. Here is an example of class block in HTML.

<!DOCTYPE html>
<html>
<head>
	<title>HTML Class Block Example</title>
	<style>
		.myclass2{background-color:red; color:white; margin:2px; padding:5px;}
		.myclass3{background-color:green; color:white; margin:2px; padding:5px;}
	</style>
</head>
<body>

<div class="myclass2">
	<h3>HTML Class Tutorial</h3>
	<p>This is HTML class tutorial. Here you will learn all about classes in HTML.</p>
</div> 
<div class="myclass3">
	<h3>HTML Class Example</h3>
	<p>This is HTML class example. Here you will find all examples related to classes in HTML.</p>
</div> 
<div class="myclass2">
	<h3>HTML Class Test</h3>
	<p>This is HTML class test. Here you will give test related to classes in HTML.</p>
</div> 

</body>
</html>

Here is the sample output produced by the above HTML class block example code:

html class example

You can also learn about classing an inline HTML elements tutorial. You will find about classing an inline HTML elements at the end of the tutorial.


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test