SlideShare a Scribd company logo
HTML Styles - CSS
Styling HTML with CSS
CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen,
paper, or in other media.
CSS saves a lot of work. It can control the layout of multiple web pages
all at once.
CSS can be added to HTML elements in 3 ways:
• Inline - by using the style attribute in HTML elements
• Internal - by using a <style> element in the <head> section
• External - by using an external CSS file
The most common way to add CSS, is to keep the styles in separate CSS
files.
CSS Syntax
A CSS rule-set consists of a selector and a declaration block:
• The selector points to the HTML element you want to style.
• The declaration block contains one or more declarations separated by semicolons.
• Each declaration includes a CSS property name and a value, separated by a colon.
• Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by
curly braces.
ID and Class
# ID’s are unique
Each element can have only one ID
Each page can have only one element with that ID
.Classes are not unique
You can use the same class on multiple elements.
You can use multiple classes on the same element.
Any styling information that needs to be applied to multiple objects on a page should be done with
a class.
CSS Selectors
• The CSS element Selector
• The CSS id Selector
• The CSS class Selector
• The CSS Universal Selector
• The CSS Grouping Selector
How To Add CSS
*When a browser reads a style sheet, it will format the HTML document according
to the information in the style sheet.
Three Ways to Insert CSS
There are three ways of inserting a style sheet:
• External CSS
• Internal CSS
• Inline CSS
External CSS
An external style sheet is used to define the style for many HTML
pages.
With an external style sheet, you can change the look of an entire web
site, by changing one file!
***An external style sheet can be written in any text editor. The file
must not contain any HTML code, and must be saved with a .css
extension.
*Each HTML page must include a reference to the external style sheet
file inside the <link> element, inside the <head> section.
External CSS
body {
background-color: coral;
}
h1 {
color: blue;
}
p {
color: red;
}
External CSS
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Internal CSS
<html>
<head>
<style>
body {background-color: coral;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
<html>
<body>
<h1 style="color:blue;">This is a Blue Heading</h1>
<p style="font-family:Verdana; color:red;">
This text is in Verdana and red</p>
</body>
</html>
CSS Fonts
The CSS color property defines the text color to be used.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used.
CSS Fonts
<html><head><style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 20px;
}
</style></head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
CSS Border, Padding and Margin
CSS Border
The CSS border property defines a border around an HTML element:
CSS Padding
The CSS padding property defines a padding (space) between the text
and the border:
CSS Margin
The CSS margin property defines a margin (space) outside the border:
CSS Border, Padding and Margin
<html><head><style>
h1 {
color: blue; font-family: verdana; font-size: 300%;
}
p{
font-family: verdana;
font-size:50px;
border:1px solid tomato;
padding:5px;
margin:50px;
}
</style></head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
CSS Table
<html>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>
Table Border and padding
Cell padding specifies the space between the cell content and its borders.
<html>
<head>
<style>
table,th,td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 10px;
}
th {
text-align: left;
}
</style>
</head>
<body>
Table - Adding Border Spacing
Border spacing specifies the space between the cells.
<html>
<head>
<style>
table,th,td {
border: 1px solid black;
padding:5px;
}
table {
border-spacing: 5px;
}
th {
text-align: left;
}
</style>
</head>
<body>
Table - Adding a Caption
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
HTML Blocks
<html>
<body>
<div>Hello</div>
<div>World</div>
<p>The DIV element is a block element, and will start on a new line.</p>
</body>
</html>
The <div> Element
<html>
<body>
<div style="background-color:black;color:white;padding:20px;">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in
the United Kingdom, with a metropolitan area of over 13 million
inhabitants.</p>
</div>
</body>
</html>
The <span> Element
The <span> element is often used as a container for some text.
The <span> element has no required attributes, but style, class and id are common.
When used together with CSS, the <span> element can be used to style parts of the text:
<html>
<body>
<h1>My <span style="color:red">Important</span> Heading</h1>
</body>
</html>

More Related Content

PPTX
Week 12 CSS - Review from last week
PPTX
Introduction to CSS
PPSX
Introduction to css
PPTX
Cascading style sheets (CSS)
PDF
Introduction to css
PPTX
Css Basics
Week 12 CSS - Review from last week
Introduction to CSS
Introduction to css
Cascading style sheets (CSS)
Introduction to css
Css Basics

What's hot (20)

PPT
Cascading Style Sheets
PPTX
Cascading Style Sheets (CSS)
PPT
Cascading Style Sheets (CSS) help
PPTX
Cascading Style Sheet (CSS)
PPT
Cascading Style Sheet | CSS
ODP
Introduction to css & its attributes with syntax
PPTX
Css starting
PPTX
CSS (Cascading Style Sheet)
PPTX
Cascading Style Sheet
PPTX
HTML and CSS
PPT
Cascading Style Sheet
ODP
PPTX
Introducing Cascading Style Sheets
PPTX
What is CSS?
PPT
Css present
PPTX
Complete Lecture on Css presentation
PPT
Introduction to Cascading Style Sheets (CSS)
PPTX
Cascading Style Sheets
Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS) help
Cascading Style Sheet (CSS)
Cascading Style Sheet | CSS
Introduction to css & its attributes with syntax
Css starting
CSS (Cascading Style Sheet)
Cascading Style Sheet
HTML and CSS
Cascading Style Sheet
Introducing Cascading Style Sheets
What is CSS?
Css present
Complete Lecture on Css presentation
Introduction to Cascading Style Sheets (CSS)
Ad

Similar to Html Styles-CSS (20)

PPTX
Introduction to Wed System And Technologies (1).pptx
PPTX
BITM3730 9-19.pptx
PPTX
BITM3730 9-20.pptx
PPTX
BITM3730Week4.pptx
PPTX
diffrent style sheets like cascading style sheets.pptx
PPTX
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
PPTX
Lecture-6.pptx
PPTX
Cascading style sheet, CSS Box model, Table in CSS
PPTX
cascading style sheets- About cascading style sheets on the selectors
DOC
Css introduction
PDF
Introduction to css
PPTX
Introduction HTML and CSS
PPTX
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
PPT
PPTX
CSS (Cascading Style Sheet)
PDF
Cascading Style Sheets
PPTX
Beginners css tutorial for web designers
PPTX
PPTX
What is CSS.pptx power point presentation
Introduction to Wed System And Technologies (1).pptx
BITM3730 9-19.pptx
BITM3730 9-20.pptx
BITM3730Week4.pptx
diffrent style sheets like cascading style sheets.pptx
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
Lecture-6.pptx
Cascading style sheet, CSS Box model, Table in CSS
cascading style sheets- About cascading style sheets on the selectors
Css introduction
Introduction to css
Introduction HTML and CSS
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
CSS (Cascading Style Sheet)
Cascading Style Sheets
Beginners css tutorial for web designers
What is CSS.pptx power point presentation
Ad

More from ispkosova (13)

PPTX
Calories
PPTX
Introduction to Windows 10
PPTX
Getting into HTML
PPTX
Week11 - Networking_3
PPTX
Week10_networking_2
PPTX
Week9_networking_1
PPTX
Week8 software (up, pl)
PPTX
Week7 software (os, ap)
PPTX
Week6 input, output and storage devices
PPTX
Week5 hardware - system unit
PPTX
Week3 intro to computer (history of comps, comps in everyday life)
PPTX
Week2 intro to computer (how comps work, types of comps)
PPTX
week4-measuring data
Calories
Introduction to Windows 10
Getting into HTML
Week11 - Networking_3
Week10_networking_2
Week9_networking_1
Week8 software (up, pl)
Week7 software (os, ap)
Week6 input, output and storage devices
Week5 hardware - system unit
Week3 intro to computer (history of comps, comps in everyday life)
Week2 intro to computer (how comps work, types of comps)
week4-measuring data

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Classroom Observation Tools for Teachers
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
GDM (1) (1).pptx small presentation for students
TR - Agricultural Crops Production NC III.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Supply Chain Operations Speaking Notes -ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPH.pptx obstetrics and gynecology in nursing
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Classroom Observation Tools for Teachers
2.FourierTransform-ShortQuestionswithAnswers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
STATICS OF THE RIGID BODIES Hibbelers.pdf

Html Styles-CSS

  • 2. Styling HTML with CSS CSS stands for Cascading Style Sheets. CSS describes how HTML elements are to be displayed on screen, paper, or in other media. CSS saves a lot of work. It can control the layout of multiple web pages all at once. CSS can be added to HTML elements in 3 ways: • Inline - by using the style attribute in HTML elements • Internal - by using a <style> element in the <head> section • External - by using an external CSS file The most common way to add CSS, is to keep the styles in separate CSS files.
  • 3. CSS Syntax A CSS rule-set consists of a selector and a declaration block: • The selector points to the HTML element you want to style. • The declaration block contains one or more declarations separated by semicolons. • Each declaration includes a CSS property name and a value, separated by a colon. • Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.
  • 4. ID and Class # ID’s are unique Each element can have only one ID Each page can have only one element with that ID .Classes are not unique You can use the same class on multiple elements. You can use multiple classes on the same element. Any styling information that needs to be applied to multiple objects on a page should be done with a class.
  • 5. CSS Selectors • The CSS element Selector • The CSS id Selector • The CSS class Selector • The CSS Universal Selector • The CSS Grouping Selector
  • 6. How To Add CSS *When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet. Three Ways to Insert CSS There are three ways of inserting a style sheet: • External CSS • Internal CSS • Inline CSS
  • 7. External CSS An external style sheet is used to define the style for many HTML pages. With an external style sheet, you can change the look of an entire web site, by changing one file! ***An external style sheet can be written in any text editor. The file must not contain any HTML code, and must be saved with a .css extension. *Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the <head> section.
  • 8. External CSS body { background-color: coral; } h1 { color: blue; } p { color: red; }
  • 9. External CSS <html> <head> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
  • 10. Internal CSS <html> <head> <style> body {background-color: coral;} h1 {color: blue;} p {color: red;} </style> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
  • 11. Inline CSS <html> <body> <h1 style="color:blue;">This is a Blue Heading</h1> <p style="font-family:Verdana; color:red;"> This text is in Verdana and red</p> </body> </html>
  • 12. CSS Fonts The CSS color property defines the text color to be used. The CSS font-family property defines the font to be used. The CSS font-size property defines the text size to be used.
  • 13. CSS Fonts <html><head><style> h1 { color: blue; font-family: verdana; font-size: 300%; } p { color: red; font-family: courier; font-size: 20px; } </style></head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body></html>
  • 14. CSS Border, Padding and Margin CSS Border The CSS border property defines a border around an HTML element: CSS Padding The CSS padding property defines a padding (space) between the text and the border: CSS Margin The CSS margin property defines a margin (space) outside the border:
  • 15. CSS Border, Padding and Margin <html><head><style> h1 { color: blue; font-family: verdana; font-size: 300%; } p{ font-family: verdana; font-size:50px; border:1px solid tomato; padding:5px; margin:50px; } </style></head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body></html>
  • 17. Table Border and padding Cell padding specifies the space between the cell content and its borders. <html> <head> <style> table,th,td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 10px; } th { text-align: left; } </style> </head> <body>
  • 18. Table - Adding Border Spacing Border spacing specifies the space between the cells. <html> <head> <style> table,th,td { border: 1px solid black; padding:5px; } table { border-spacing: 5px; } th { text-align: left; } </style> </head> <body>
  • 19. Table - Adding a Caption <table style="width:100%"> <caption>Monthly savings</caption> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$50</td> </tr> </table>
  • 20. HTML Blocks <html> <body> <div>Hello</div> <div>World</div> <p>The DIV element is a block element, and will start on a new line.</p> </body> </html>
  • 21. The <div> Element <html> <body> <div style="background-color:black;color:white;padding:20px;"> <h2>London</h2> <p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> </div> </body> </html>
  • 22. The <span> Element The <span> element is often used as a container for some text. The <span> element has no required attributes, but style, class and id are common. When used together with CSS, the <span> element can be used to style parts of the text: <html> <body> <h1>My <span style="color:red">Important</span> Heading</h1> </body> </html>