Chapter 2 CSS (define classes in css) | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

Chapter 2 CSS (define classes in css)

Date- Dec 09,2023

1675

In HTML, you can define classes using Cascading Style Sheets (CSS) to apply specific styling to multiple HTML elements. Here's how you can define classes in CSS within an HTML document:

CSS Class Definition within HTML:

You can define styles within a <style> tag in the <head> section of your HTML file or link an external CSS file that contains your class definitions.

Internal Styles (within the HTML file):

<html> <head> <style> /* Define a class named 'highlight' */ .highlight { color: red; font-weight: bold; } /* Define another class named 'box' */ .box { border: 1px solid #000; padding: 10px; } </style> </head> <body> <!-- HTML content with applied classes --> <p class="highlight">This text is styled using the 'highlight' class.</p> <div class="box">This is a box with a border and padding.</div> </body> </html>


Applying Classes to HTML Elements:

You can apply the defined classes by using the class attribute in HTML elements.

<!-- HTML content with applied classes --> <p class="highlight">This text is styled using the 'highlight' class.</p> <div class="box">This is a box with a border and padding.</div>

In this example,

  • 1. The class attribute is used to assign the highlight and box classes to a paragraph (<p>) and a div (<div>) element, respectively.
  • 2. The styles defined for the classes in the<style> tag or an external CSS file will be applied to the elements with those classes.

This approach allows you to define styles within your HTML file directly, but for better organization and maintainability, it's common to use an external CSS file to define classes and link it to the HTML file using the <link> tag in the <head> section.





Result:-




Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1210
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts