HTML Classes

The HTML class attribute is used to specify a single or multiple class names for an HTML element. We can use this class in CSS with a specific class, write a period (.) character, followed by the name of the class for selecting elements.

A class attribute can be defined within <style> tag or in separate file using the (.) character.

Example

<head>  

    <style>  

        .headings{   

            color: lightgreen;  

            font-family: cursive;  

            background-color: black; }  

    </style>  

</head>  

Multiple Classes

You can use multiple class names (more than one) with HTML elements. These class names must be separated by a space.

Example

<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<head>
<style>    
.multiple {    
    background-color: blue;    
    color: white;    
    padding: 10px;    
}     
    
.center {    
    text-align: center;    
}    
</style>  
</head>
<body>
<h2>Multiple Classes</h2>    
<p>The correct place for easy learning.....</p>    
    
<h2 class="multiple center">C Programming</h2>    
<h2 class="multiple">HTML</h2>    
<h2 class="multiple">CSS</h2>    
    
</body>
</html> 

Output




No comments:

Post a Comment