CSS stands for Cascading Style Sheets. It is used to control the appearance, layout, and presentation of HTML webpages.
HTML creates the structure of a webpage, while CSS makes that webpage attractive and organized.
For example:
<h1>DSD Education</h1>
With CSS:
h1 {
color: #f97316;
text-align: center;
font-size: 36px;
}
After completing this lesson, students will be able to:
CSS (Cascading Style Sheets) is a stylesheet language used to style HTML documents.
CSS can control:
<h1>Advanced Computer Applications</h1>
<p>Learn professional computer skills.</p>
CSS:
h1 {
color: orange;
}
p {
font-size: 18px;
}
| HTML | CSS |
|---|---|
| Creates webpage structure | Styles webpage |
| Creates headings | Changes heading appearance |
| Creates paragraphs | Controls paragraph styling |
| Creates buttons | Styles buttons |
| Creates tables | Styles tables |
| Creates forms | Styles forms |
| Provides content | Controls presentation |
Simple rule:
HTML = Structure
CSS = Design
A CSS rule generally contains a selector, property, and value.
selector {
property: value;
}
Example:
h1 {
color: blue;
font-size: 32px;
}
Here:
h1 → Selectorcolor → Propertyblue → Valuefont-size → Property32px → ValueEach declaration normally ends with a semicolon ;.
There are three common ways to apply CSS.
CSS is written directly inside an HTML element.
<h1 style="color: red;">Welcome to DSD Education</h1>
Useful for applying a quick style to one specific element.
It becomes difficult to maintain when many elements need styling.
Internal CSS is written inside the <style> element, usually in the <head> section.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
text-align: center;
}
p {
font-size: 18px;
}
</style>
</head>
<body>
<h1>DSD Education</h1>
<p>Welcome to our computer course.</p>
</body>
</html>
Internal CSS is useful when styling a single HTML page.
External CSS is stored in a separate .css file.
For example:
index.html
style.css
<link rel="stylesheet" href="style.css">
h1 {
color: orange;
text-align: center;
}
p {
font-size: 18px;
}
External CSS is generally preferred for larger websites because one stylesheet can be reused across multiple pages.
Selectors tell CSS which HTML elements should be styled.
Common selectors include:
Selects HTML elements by their tag name.
p {
color: black;
}
This applies to all <p> elements.
A class selector starts with a period ..
HTML:
<p class="highlight">Important information</p>
CSS:
.highlight {
color: red;
font-weight: bold;
}
A class can be used on multiple elements.
An ID selector starts with #.
HTML:
<h1 id="main-heading">DSD Education</h1>
CSS:
#main-heading {
color: blue;
}
An ID should normally identify one unique element within a page.
The universal selector * selects all elements.
* {
margin: 0;
padding: 0;
}
It is commonly used for basic CSS resets.
Multiple selectors can be styled together.
h1, h2, h3 {
color: #f97316;
}
CSS comments are written as:
/* This is a CSS comment */
Comments help developers understand and organize their stylesheet.
CSS allows different ways to specify colors.
h1 {
color: red;
}
h1 {
color: #f97316;
}
h1 {
color: rgb(249, 115, 22);
}
RGBA can include transparency.
div {
background-color: rgba(0, 0, 0, 0.5);
}
CSS can control the background of elements.
body {
background-color: #f5f5f5;
}
Other background properties include:
background-image
background-repeat
background-position
background-size
background-attachment
Example:
.banner {
background-image: url("banner.jpg");
background-size: cover;
background-position: center;
}
CSS provides several properties for styling text.
p {
color: #333;
text-align: left;
text-decoration: none;
text-transform: none;
line-height: 1.6;
letter-spacing: 0.5px;
}
| Property | Purpose |
|---|---|
color |
Text color |
text-align |
Text alignment |
text-decoration |
Underline/decoration |
text-transform |
Uppercase/lowercase |
line-height |
Space between lines |
letter-spacing |
Space between characters |
word-spacing |
Space between words |
CSS can control fonts.
body {
font-family: Arial, sans-serif;
}
h1 {
font-size: 36px;
font-weight: 700;
}
Common font properties:
font-familyfont-sizefont-weightfont-stylefont-variantExample:
p {
font-family: Arial, sans-serif;
font-size: 18px;
font-style: normal;
font-weight: 400;
}
CSS can control the size of elements.
.box {
width: 400px;
height: 200px;
}
Percentage values can also be used:
.container {
width: 80%;
}
Modern layouts also commonly use:
max-width: 1200px;
min-height: 300px;
Borders can be added around elements.
.box {
border: 2px solid black;
}
Individual properties include:
border-width
border-style
border-color
border-radius
Example:
.card {
border: 1px solid #ddd;
border-radius: 10px;
}
border-radius is used to create rounded corners.
Margin creates space outside an element.
.box {
margin: 20px;
}
Individual sides can be controlled:
.box {
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;
}
Padding creates space between the content and the element’s border.
.box {
padding: 20px;
}
Example:
.card {
border: 1px solid #ddd;
padding: 20px;
}
| Margin | Padding |
|---|---|
| Space outside the element | Space inside the element |
| Separates elements | Separates content from border |
| Outside border | Inside border |
Every HTML element can be understood using the CSS Box Model.
+---------------------------+
| Margin |
| +---------------------+ |
| | Border | |
| | +---------------+ | |
| | | Padding | | |
| | | +-----------+ | | |
| | | | Content | | | |
| | | +-----------+ | | |
| | +---------------+ | |
| +---------------------+ |
+---------------------------+
The four main parts are:
box-sizingA commonly used CSS rule is:
* {
box-sizing: border-box;
}
With border-box, the declared width and height include the element’s padding and border.
This makes sizing easier to manage in many layouts.
HTML:
<a href="#">Visit Our Website</a>
CSS:
a {
color: blue;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
The :hover pseudo-class applies styles when the mouse pointer is over the link.
ul {
list-style-type: square;
}
ol {
list-style-type: decimal;
}
CSS can also control spacing and positioning of list items.
li {
margin-bottom: 8px;
}
HTML:
<table>
<tr>
<th>Course</th>
<th>Duration</th>
</tr>
<tr>
<td>ADCA</td>
<td>12 Months</td>
</tr>
</table>
CSS:
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: left;
}
th {
background-color: #f97316;
}
HTML:
<button>Register Now</button>
CSS:
button {
background-color: #f97316;
color: white;
padding: 12px 24px;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:hover {
opacity: 0.9;
}
CSS can make buttons more attractive and user-friendly.
img {
max-width: 100%;
height: auto;
}
This helps an image stay within its container.
For rounded images:
.profile-image {
width: 150px;
height: 150px;
border-radius: 50%;
}
The display property controls how an element participates in layout.
Common values include:
display: block;
display: inline;
display: inline-block;
display: none;
Example:
span {
display: inline-block;
}
display: none removes an element from the normal page layout.
The position property controls how an element is positioned.
Common values:
staticrelativeabsolutefixedstickyExample:
.box {
position: relative;
}
A positioned element can then be adjusted using properties such as:
top
right
bottom
left
Pseudo-classes style elements according to a particular state.
Examples:
a:hover {
color: red;
}
input:focus {
border-color: blue;
}
button:active {
transform: scale(0.98);
}
Common pseudo-classes include:
:hover:focus:active:visited:first-child:last-childWhen multiple CSS rules target the same element, CSS determines which rule has greater priority.
A simplified order is:
Inline styles > ID selectors > Class/attribute/pseudo-class selectors > Element selectors
Example:
p {
color: black;
}
.text {
color: blue;
}
#special {
color: red;
}
If the same paragraph has both the class and ID, the ID rule generally has higher specificity.
CSS uses different units for measurements.
font-size: 20px;
width: 80%;
font-size: 1rem;
width: 50vw;
height: 50vh;
Common units:
| Unit | Meaning |
|---|---|
px |
Pixels |
% |
Percentage |
em |
Relative to font size of relevant parent |
rem |
Relative to root font size |
vw |
Viewport width |
vh |
Viewport height |
Create two files:
index.html
style.css
index.html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ADCA Course</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="header">
<h1>DSD Education</h1>
<p>Advanced Diploma in Computer Applications</p>
</header>
<main>
<section class="course-card">
<h2>ADCA Course</h2>
<p>
Learn computer applications, MS Office,
Internet, C Programming, HTML and CSS.
</p>
<h3>Course Subjects</h3>
<ul>
<li>Computer Fundamentals</li>
<li>MS Word</li>
<li>MS Excel</li>
<li>Internet & Networking</li>
<li>C Programming</li>
<li>HTML & CSS</li>
</ul>
<button>Enquire Now</button>
</section>
</main>
<footer>
<p>© 2026 DSD Education</p>
</footer>
</body>
</html>
style.css* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, sans-serif;
background-color: #f5f5f5;
color: #333;
}
.header {
text-align: center;
padding: 40px 20px;
background-color: #f97316;
color: white;
}
.header h1 {
margin: 0 0 10px;
font-size: 36px;
}
.header p {
margin: 0;
font-size: 18px;
}
.course-card {
max-width: 700px;
margin: 40px auto;
padding: 30px;
background-color: white;
border: 1px solid #ddd;
border-radius: 12px;
}
.course-card h2 {
margin-top: 0;
font-size: 30px;
}
.course-card li {
margin-bottom: 8px;
}
button {
padding: 12px 24px;
border: none;
border-radius: 6px;
background-color: #f97316;
color: white;
cursor: pointer;
}
button:hover {
opacity: 0.9;
}
footer {
text-align: center;
padding: 20px;
}
CSS, Stylesheet, Selector, Property, Value, Class, ID, Inline CSS, Internal CSS, External CSS, Color, Background, Font, Border, Margin, Padding, Box Model, Display, Position, Pseudo-class, Specificity, CSS Unit
Leave a Reply