SlideShare a Scribd company logo
CSS for Styling HTML
Contents
CS380
1
Cascading Style Sheets (CSS)
 CSS use to describes the appearance, layout,
and presentation of information on a web page
 CSS Advantages:
2
•Separates structure from presentation
•Provides advanced control of presentation
•Easy maintenance of multiple pages
•Faster page loading
•Better accessibility for disabled users
•Easy to learn
Basic CSS rule syntax
 A CSS file consists of one or more rules
 Each rule starts with a selector
 A selector specifies an HTML element(s) and then
applies style properties to them
3
SYNTAX to Write CSS=
selector {
property: value;
...
property: value;
} CSS
Example===
p {
font-family: sans-serif;
color: red;
}
Types of CSS or
Attaching a Style Sheet
Attach a style sheet to a page by adding the code to the
<head> section of the HTML page. There are 3 ways to attach
CSS to a page:
1. External Style Sheet: Best used to control styling on multiple
pages.
<link rel="stylesheet" type="text/css"
media="all" href="css/styles.css" />
2. Internal Style Sheet: Best used to control styling on one page.
<style type=“text/css”>
h1 {color: red)
</style>
3. Inline Style Sheet*: CSS is not attached in the <header> but is
used directly within HTML tags.
<p style=“color: red”>Some Text</p>
Types of CSS- External CSS
 A page can link to multiple style sheet file.
 It uses Two fils-1 .CSS and 2. .HTML
5
P{color:red;} style.CSS
<head>
<link href="style.css" rel="stylesheet" /></head>
<body><p>This is External CSS</p>
.HTML
CS380
Internal CSS:
 It apply on Single Page.
 It uses <style> Tag in <head> and </head>.
6
<head>
<style>
p { font-family: arial;
color: red; }
h2 { background-color: yellow; }
</style>
</head> <body><h1>Internal CSS</h1>
<p>This is Internal CSS</p></body>
HTML
CS380
Inline styles: the style attribute
 It apply on single line of HTML code.
 It uses style as attribute.
 Higher precedence than internal or external CSS styles
7
<p style="font-family: chiller; color: red;">
This is a paragraph</p>
HTML
CS380
CSS properties for colors
8
p {
color: red;
background-color: yellow;
}
CSS
CS380
This paragraph uses the style above output
property description
color color of the element's text
background-color
color that will appear behind the
element
CSS comments /*…*/
9
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
 CSS (like HTML) is usually not commented as rigorously
as programming languages such as Java
 The // single-line comment style is NOT supported in
CSS
 The <!-- ... --> HTML comment style is also NOT
supported in CSS
CS380
CSS properties for fonts
property description
font-family which font will be used
font-size how large the letters will be drawn
font-style used to enable/disable italic style
font-weight used to enable/disable bold style
CS380
10
<html>
<head><style>
p {
font-family :chiller;
font-size :20px;
font-style :italic;
font-weight :bold
} </style></head><body>
<p> This text formatted with font properties</p></body></html
Example:
CSS properties for text
property description
text-align alignment of text within its element
text-decoration decorations such as underlining
line-height,
word-spacing,
letter-spacing
gaps between the various portions
of the text
text-indent
indents the first letter of each
paragraph
CS380
11
Example
CS380
12
<html>
<head><style>
p {
line-height:12px;
Text-align: center;
Text-decoration:Overline;
Text-transform: uppercase;
word-spacing:20px;
letter-spacing:30px;
} </style></head><body>
<p> This text formatted with text properties</p></body></html
Example:
CSS properties for backgrounds
property description
background-color color to fill background
background-image image to place in background
background-position
placement of bg image within
element
background-repeat
whether/how bg image should be
repeated
CS380
13
Example:
CS380
14
<html>
<head><style>
body{
background-color:red;
Background-image:url(image1.jpg);
background-position:right;
Background-repeat:no-repeat;
Background-size: 200px 300px;
} </style></head><body>
<p> This page formatted with background
properties</p></body></html
CSS Box Model Properties:
CS380
15
property description
height To Change height of Section.
width To Change width of Section.
margin
Use to define margin space along
with four side
Padding
Use to define space along with
four side between border and
content.
Border
Use to define border around
content
Example:
CS380
16
<html>
<head><style>
div{
Hight:300px;
Width:300px;
Border: solid 20px red;
Margin-left:50px;
Padding:30px; //apply to for side
} </style></head><body>
<div>
<p> This section formatted with box model
properties</p></div></body></html

More Related Content

ODP
Introduction to css & its attributes with syntax
PPTX
Cascading Style Sheet (CSS)
PPT
Cascading Style Sheet | CSS
PPT
Cascading Style Sheets
PPTX
Cascading Style Sheet
PPTX
Cascading Style Sheets (CSS)
Introduction to css & its attributes with syntax
Cascading Style Sheet (CSS)
Cascading Style Sheet | CSS
Cascading Style Sheets
Cascading Style Sheet
Cascading Style Sheets (CSS)

What's hot (20)

PPTX
CSS (Cascading Style Sheet)
PPTX
Cascading style sheets (CSS)
PDF
Introduction to css
PPSX
Introduction to css
PPTX
Complete Lecture on Css presentation
PPT
Cascading Style Sheets (CSS) help
PPT
Cascading style sheet (css)]
PPTX
Week 12 CSS - Review from last week
PPTX
Introducing Cascading Style Sheets
PPT
CSS
PDF
HTML CSS Basics
PPT
Introduction to Cascading Style Sheets (CSS)
PPT
Introduction to CSS
PPTX
Css introduction
PPTX
CSS Basics (Cascading Style Sheet)
PPTX
Beginners css tutorial for web designers
PPTX
Introduction to web design discussing which languages is used for website des...
CSS (Cascading Style Sheet)
Cascading style sheets (CSS)
Introduction to css
Introduction to css
Complete Lecture on Css presentation
Cascading Style Sheets (CSS) help
Cascading style sheet (css)]
Week 12 CSS - Review from last week
Introducing Cascading Style Sheets
CSS
HTML CSS Basics
Introduction to Cascading Style Sheets (CSS)
Introduction to CSS
Css introduction
CSS Basics (Cascading Style Sheet)
Beginners css tutorial for web designers
Introduction to web design discussing which languages is used for website des...
Ad

Similar to Css basic (20)

PPTX
properties of css.pptx power pointpresentation
PPTX
Introduction HTML and CSS
PPTX
What is CSS.pptx power point presentation
PPT
working with internet technologies using CSS
PPTX
Lecture-6.pptx
PPTX
PDF
Unit 3 (it workshop).pptx
PPT
Css siva
PPT
Css siva
PDF
Chapter 3 - CSS.pdf
PPT
Cascading Style Sheet
PPTX
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
PPT
Make Css easy : easy tips for css
PDF
4. Web Technology CSS Basics-1
ODP
CSS Basics
PDF
cascading style sheets ppt.sildeshower phone view
PPTX
Cascading Styling Sheets(CSS) simple design language intended to transform th...
PPT
CSS Training in Bangalore
PPTX
PPTX
CSS____4563276__HTML___________0989.pptx
properties of css.pptx power pointpresentation
Introduction HTML and CSS
What is CSS.pptx power point presentation
working with internet technologies using CSS
Lecture-6.pptx
Unit 3 (it workshop).pptx
Css siva
Css siva
Chapter 3 - CSS.pdf
Cascading Style Sheet
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
Make Css easy : easy tips for css
4. Web Technology CSS Basics-1
CSS Basics
cascading style sheets ppt.sildeshower phone view
Cascading Styling Sheets(CSS) simple design language intended to transform th...
CSS Training in Bangalore
CSS____4563276__HTML___________0989.pptx
Ad

Recently uploaded (20)

PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Quality Control Management for RMG, Level- 4, Certificate
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PPT
Machine printing techniques and plangi dyeing
PPTX
building Planning Overview for step wise design.pptx
PDF
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PDF
Urban Design Final Project-Context
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PDF
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
PPTX
HPE Aruba-master-icon-library_052722.pptx
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPT
UNIT I- Yarn, types, explanation, process
PPTX
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPTX
Wisp Textiles: Where Comfort Meets Everyday Style
PPTX
12. Community Pharmacy and How to organize it
PDF
SEVA- Fashion designing-Presentation.pdf
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Quality Control Management for RMG, Level- 4, Certificate
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Machine printing techniques and plangi dyeing
building Planning Overview for step wise design.pptx
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
Urban Design Final Project-Context
DOC-20250430-WA0014._20250714_235747_0000.pptx
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
Tenders & Contracts Works _ Services Afzal.pptx
HPE Aruba-master-icon-library_052722.pptx
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
UNIT I- Yarn, types, explanation, process
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Wisp Textiles: Where Comfort Meets Everyday Style
12. Community Pharmacy and How to organize it
SEVA- Fashion designing-Presentation.pdf

Css basic

  • 1. CSS for Styling HTML Contents CS380 1
  • 2. Cascading Style Sheets (CSS)  CSS use to describes the appearance, layout, and presentation of information on a web page  CSS Advantages: 2 •Separates structure from presentation •Provides advanced control of presentation •Easy maintenance of multiple pages •Faster page loading •Better accessibility for disabled users •Easy to learn
  • 3. Basic CSS rule syntax  A CSS file consists of one or more rules  Each rule starts with a selector  A selector specifies an HTML element(s) and then applies style properties to them 3 SYNTAX to Write CSS= selector { property: value; ... property: value; } CSS Example=== p { font-family: sans-serif; color: red; }
  • 4. Types of CSS or Attaching a Style Sheet Attach a style sheet to a page by adding the code to the <head> section of the HTML page. There are 3 ways to attach CSS to a page: 1. External Style Sheet: Best used to control styling on multiple pages. <link rel="stylesheet" type="text/css" media="all" href="css/styles.css" /> 2. Internal Style Sheet: Best used to control styling on one page. <style type=“text/css”> h1 {color: red) </style> 3. Inline Style Sheet*: CSS is not attached in the <header> but is used directly within HTML tags. <p style=“color: red”>Some Text</p>
  • 5. Types of CSS- External CSS  A page can link to multiple style sheet file.  It uses Two fils-1 .CSS and 2. .HTML 5 P{color:red;} style.CSS <head> <link href="style.css" rel="stylesheet" /></head> <body><p>This is External CSS</p> .HTML CS380
  • 6. Internal CSS:  It apply on Single Page.  It uses <style> Tag in <head> and </head>. 6 <head> <style> p { font-family: arial; color: red; } h2 { background-color: yellow; } </style> </head> <body><h1>Internal CSS</h1> <p>This is Internal CSS</p></body> HTML CS380
  • 7. Inline styles: the style attribute  It apply on single line of HTML code.  It uses style as attribute.  Higher precedence than internal or external CSS styles 7 <p style="font-family: chiller; color: red;"> This is a paragraph</p> HTML CS380
  • 8. CSS properties for colors 8 p { color: red; background-color: yellow; } CSS CS380 This paragraph uses the style above output property description color color of the element's text background-color color that will appear behind the element
  • 9. CSS comments /*…*/ 9 /* This is a comment. It can span many lines in the CSS file. */ p { color: red; background-color: aqua; } CSS  CSS (like HTML) is usually not commented as rigorously as programming languages such as Java  The // single-line comment style is NOT supported in CSS  The <!-- ... --> HTML comment style is also NOT supported in CSS CS380
  • 10. CSS properties for fonts property description font-family which font will be used font-size how large the letters will be drawn font-style used to enable/disable italic style font-weight used to enable/disable bold style CS380 10 <html> <head><style> p { font-family :chiller; font-size :20px; font-style :italic; font-weight :bold } </style></head><body> <p> This text formatted with font properties</p></body></html Example:
  • 11. CSS properties for text property description text-align alignment of text within its element text-decoration decorations such as underlining line-height, word-spacing, letter-spacing gaps between the various portions of the text text-indent indents the first letter of each paragraph CS380 11
  • 12. Example CS380 12 <html> <head><style> p { line-height:12px; Text-align: center; Text-decoration:Overline; Text-transform: uppercase; word-spacing:20px; letter-spacing:30px; } </style></head><body> <p> This text formatted with text properties</p></body></html Example:
  • 13. CSS properties for backgrounds property description background-color color to fill background background-image image to place in background background-position placement of bg image within element background-repeat whether/how bg image should be repeated CS380 13
  • 15. CSS Box Model Properties: CS380 15 property description height To Change height of Section. width To Change width of Section. margin Use to define margin space along with four side Padding Use to define space along with four side between border and content. Border Use to define border around content
  • 16. Example: CS380 16 <html> <head><style> div{ Hight:300px; Width:300px; Border: solid 20px red; Margin-left:50px; Padding:30px; //apply to for side } </style></head><body> <div> <p> This section formatted with box model properties</p></div></body></html

Editor's Notes

  • #5: 4
  • #6: a conflict (two sheets define a style for the same HTML element