SlideShare a Scribd company logo
Web Programming
SYED SHAHZAIB SOHAIL
Lecture 5
Introduction to CSS
Contents
• What is CSS?
• Why use CSS?
• Ways to use CSS
• Big Problem
• CSS Syntax
• CSS Selectors and its types
• Grouping Selectors
• CSS Comments
What is CSS?
• CSS stands for Cascading Style Sheets
• CSS defines the presentation ofWeb Pages
• 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 at
once
Why use CSS?
• CSS is used to defines styles of your web pages, including the design, layout
and variations in display for different devices and screen sizes.
Ways to use CSS
• CSS can be used in 3 different ways.
• Inline CSS
• Internal CSS
• External CSS
Continued…
• Inline CSS
• Inline CSS allows you to apply a unique style to one HTML element at a time.
• You assign CSS to a specific HTML tag by using style attribute with any CSS properties
defined within it.
• Inline CSS style will always override style properties determined in internal or external
files.
<p style=“color: blue;”>This is a paragraph</p>
This is a paragraph
Continued…
• Internal CSS
• The internal style sheet is used to add a unique style for a single document.
• It is defined in <head> section of the HTML page inside the <style> tag.
Continued…
• External CSS
• The external style sheet is generally used when you want to make changes on multiple pages.
• It is ideal for this condition because it facilitates you to change the look of the entire website by
changing just one file.
• It used the <link> tag on every pages and the <link> tag should be put inside the head section.
<head>
<link rel=“stylesheet” type=“text/css” href=“style.css”>
</head>
• The external style sheet may be written in text editor but must be saved with a .css extension.This
file should not contain HTML elements
•What style will be used when there is more than one
style specified for an HTML element?
Continued…
• If there are multiple style sheets the priority level is defined as following:
1. Inline style sheet
2. Internal style sheet
3. External style sheet
Big Problem
• HTML was never intended to contain tags for formatting a web page
• HTML was created to describe the content of the web page
• When tags like <font> and color attributes were added to the HTML 3.2
specification, it started a nightmare for web developers. Development of large
websites, where fonts and color information were added to every single page,
became a long and expensive process
• To solve this problem, theWorld Wide Web Consortium (W3C) created CSS that
removed the style formatting from the HTML page
CSS Syntax
• A CSS rule-set consists of a selector and a declaration block:
H1 {color:blue; font-size:12px;}
Selector Declaration Declaration
Property Value Property Value
Continued...
• 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
semicolon
• A CSS declaration always ends with a semicolon and declaration blocks are
surrounded by curly braces
CSS Selectors
• CSS selectors are used to “find” (or select) HTML elements based on their
element name, id, class, attribute and more
Types of CSS Selectors
• There are 3 types of CSS selectors
• Element Selector
• Id Selector
• Class Selector
• Child Selector
• Attribute Selector
Continued…
• Element Selector
• The element selector selects elements based on the element name.
• Id Selector
• The id selector used the id attribute of an HTML element to select a specific element.
• The id of an element should be unique within a page, so the id selector is used to select
one unique element.
• To select an element with a specific id, write a hash character, followed by the id of the
element.
Continued…
• Class Selector
• The class selector selects elements with a specific class attribute.
• To select elements with a specific class, write a period character, followed by the name of
the class.
.center {text-align: center; color: red;}
• You can also specify that only specific HTML elements should be affected by a class.
p. center {text-align: center; color: red;}
• HTML elements can also refer to more than one class.
<p class=“center large”>This paragraph refers to two classes</p>
Continued…
• Child Selector
body > p {color: #000000;}
• Attribute Selector
• You can also apply styles to HTML elements with particular attributes
• input[type=“text”] {color: #000000;}
Grouping Selectors
• If you have elements with the same style definitions, like
• h1 {text-align: center; color: red;}
• h2 {text-align: center; color: red;}
• p {text-align: center; color: red;}
• It will be better to group the selectors, to minimize the code.
• To group selectors, separate each selector with a comma.
• h1, h2, p {text-align: center; color: red;}
CSS Comments
• Comments are used to explain the code, and may help when you edit the
source code at a later date
• Comments are ignored by browsers
• A CSS comment starts with /* and ends with */
• Single Line and Multiline Comments

More Related Content

What's hot (20)

PDF
Html
Kamal Acharya
 
PPT
Introduction to CSS
Amit Tyagi
 
PPT
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
PPTX
Responsive web design with html5 and css3
Divya Tiwari
 
PPTX
Html and css
Sukrit Gupta
 
PPTX
Css types internal, external and inline (1)
Webtech Learning
 
PPTX
chitra
sweet chitra
 
PPTX
What is CSS?
HalaiHansaika
 
PPTX
Ia css
osman do
 
PPTX
CSS (Cascading Style Sheet)
Harshit Srivastava
 
PPT
CSS 101
dunclair
 
PPTX
Complete Lecture on Css presentation
Salman Memon
 
PPTX
Cascading Style Sheets - CSS
Sun Technlogies
 
PDF
Web Development 3 (HTML & CSS)
ghayour abbas
 
PPTX
Cascading style sheets
smitha273566
 
PPTX
CSS Basic Introduction, Rules, And Tips
Reema
 
PDF
Web Development 1 (HTML & CSS)
ghayour abbas
 
Introduction to CSS
Amit Tyagi
 
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
Responsive web design with html5 and css3
Divya Tiwari
 
Html and css
Sukrit Gupta
 
Css types internal, external and inline (1)
Webtech Learning
 
chitra
sweet chitra
 
What is CSS?
HalaiHansaika
 
Ia css
osman do
 
CSS (Cascading Style Sheet)
Harshit Srivastava
 
CSS 101
dunclair
 
Complete Lecture on Css presentation
Salman Memon
 
Cascading Style Sheets - CSS
Sun Technlogies
 
Web Development 3 (HTML & CSS)
ghayour abbas
 
Cascading style sheets
smitha273566
 
CSS Basic Introduction, Rules, And Tips
Reema
 
Web Development 1 (HTML & CSS)
ghayour abbas
 

Similar to Web Development - Lecture 5 (20)

PPTX
Cascading Style Sheets for web browser.pptx
alvindalejoyosa1
 
PPTX
cascading style sheets- About cascading style sheets on the selectors
JayanthiM19
 
PPTX
Lecture-6.pptx
vishal choudhary
 
PPT
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
PPTX
Ifi7174 lesson2
Sónia
 
PPT
Learning CSS for beginners.ppt all that are but
DangyiGodSees
 
PPT
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
PPT
CSS Training in Bangalore
rajkamal560066
 
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Erin M. Kidwell
 
PPTX
Lecture 3CSS part 1.pptx
GmachImen
 
PPTX
Lecture 9 CSS part 1.pptxType Classification
ZahouAmel1
 
PPTX
Introduction to CSS
Shehzad Yaqoob
 
PPTX
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
PPTX
Building Next Generation Websites Session5
Muhammad Ehtisham Siddiqui
 
PPTX
Introduction to CSS.pptx web for web web
compengwaelalahmar
 
PPTX
WEB TECHNOLOGY Unit-2.pptx
karthiksmart21
 
PPTX
Cascading Styling Sheets(CSS) simple design language intended to transform th...
JebaRaj26
 
PDF
Introduction to css
Joseph Gabriel
 
PPTX
LIS3353 SP12 Week 13
Amanda Case
 
Cascading Style Sheets for web browser.pptx
alvindalejoyosa1
 
cascading style sheets- About cascading style sheets on the selectors
JayanthiM19
 
Lecture-6.pptx
vishal choudhary
 
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
Ifi7174 lesson2
Sónia
 
Learning CSS for beginners.ppt all that are but
DangyiGodSees
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
CSS Training in Bangalore
rajkamal560066
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Erin M. Kidwell
 
Lecture 3CSS part 1.pptx
GmachImen
 
Lecture 9 CSS part 1.pptxType Classification
ZahouAmel1
 
Introduction to CSS
Shehzad Yaqoob
 
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session5
Muhammad Ehtisham Siddiqui
 
Introduction to CSS.pptx web for web web
compengwaelalahmar
 
WEB TECHNOLOGY Unit-2.pptx
karthiksmart21
 
Cascading Styling Sheets(CSS) simple design language intended to transform th...
JebaRaj26
 
Introduction to css
Joseph Gabriel
 
LIS3353 SP12 Week 13
Amanda Case
 
Ad

Recently uploaded (20)

PDF
07/25 - LOUIS VUITTON - DUBAI - UAE_MAURO MANCINI PM ANTEFIXE
Mauro Mancini
 
PPTX
In the sweet by and by, We shall meet on that beautiful shore; In the sweet b...
kuysniya14
 
PPTX
4. PMES PORTFOLIO_BROWN DESIGN_T1-T3_A4.pptx
GynnelNicanor1
 
PPTX
condylar pptx.in relation to dental seurgery
abishekgowtham586
 
PDF
IDES-502_Project-1-Home_Presentation-Boards_Codamon.pdf
codamona
 
PPTX
Face ATM nadar saraswathi college of arts and science, vadaputhupatti- Full....
priyaayalraj
 
PDF
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
PDF
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
PDF
PHILGOV-QUIZ-_20250625_182551_000.pdfhehe
errollnas3
 
DOCX
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
PDF
Ddivine School's Interior Architects .pdf
divinebuildstone
 
DOCX
Ai vehicle traffic signal detector research proposal.docx
DavidNameza
 
PDF
Favorite Looks Menswear Spring Summer 2026
Ana Andjelic
 
PPTX
N-doped FSHC 2nrdddddddddddddddddrrrd.pptx
71762306019
 
DOCX
Non_Communicable_Diseases_Risk_Assessment,_Prevention,_Control,.docx
DrFatemaTuzzannat
 
PPTX
Transportation in the air, sea and land.pptx
KhloodAli5
 
PPTX
SAMPLE FILE OF-PPT-FINAL-ORAL-DEFENSE.pptx
Yvez2
 
PPTX
619813902-Fun-friday-Identify-Bollywood-movie-from-dialogues-deliver-the-dial...
in4withme
 
PPTX
sCREW cONVEYOR AUGER DAF SLUDGE SYSTEM TO
viksurs
 
PPTX
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
07/25 - LOUIS VUITTON - DUBAI - UAE_MAURO MANCINI PM ANTEFIXE
Mauro Mancini
 
In the sweet by and by, We shall meet on that beautiful shore; In the sweet b...
kuysniya14
 
4. PMES PORTFOLIO_BROWN DESIGN_T1-T3_A4.pptx
GynnelNicanor1
 
condylar pptx.in relation to dental seurgery
abishekgowtham586
 
IDES-502_Project-1-Home_Presentation-Boards_Codamon.pdf
codamona
 
Face ATM nadar saraswathi college of arts and science, vadaputhupatti- Full....
priyaayalraj
 
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
PHILGOV-QUIZ-_20250625_182551_000.pdfhehe
errollnas3
 
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
Ddivine School's Interior Architects .pdf
divinebuildstone
 
Ai vehicle traffic signal detector research proposal.docx
DavidNameza
 
Favorite Looks Menswear Spring Summer 2026
Ana Andjelic
 
N-doped FSHC 2nrdddddddddddddddddrrrd.pptx
71762306019
 
Non_Communicable_Diseases_Risk_Assessment,_Prevention,_Control,.docx
DrFatemaTuzzannat
 
Transportation in the air, sea and land.pptx
KhloodAli5
 
SAMPLE FILE OF-PPT-FINAL-ORAL-DEFENSE.pptx
Yvez2
 
619813902-Fun-friday-Identify-Bollywood-movie-from-dialogues-deliver-the-dial...
in4withme
 
sCREW cONVEYOR AUGER DAF SLUDGE SYSTEM TO
viksurs
 
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
Ad

Web Development - Lecture 5

  • 3. Contents • What is CSS? • Why use CSS? • Ways to use CSS • Big Problem • CSS Syntax • CSS Selectors and its types • Grouping Selectors • CSS Comments
  • 4. What is CSS? • CSS stands for Cascading Style Sheets • CSS defines the presentation ofWeb Pages • 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 at once
  • 5. Why use CSS? • CSS is used to defines styles of your web pages, including the design, layout and variations in display for different devices and screen sizes.
  • 6. Ways to use CSS • CSS can be used in 3 different ways. • Inline CSS • Internal CSS • External CSS
  • 7. Continued… • Inline CSS • Inline CSS allows you to apply a unique style to one HTML element at a time. • You assign CSS to a specific HTML tag by using style attribute with any CSS properties defined within it. • Inline CSS style will always override style properties determined in internal or external files. <p style=“color: blue;”>This is a paragraph</p> This is a paragraph
  • 8. Continued… • Internal CSS • The internal style sheet is used to add a unique style for a single document. • It is defined in <head> section of the HTML page inside the <style> tag.
  • 9. Continued… • External CSS • The external style sheet is generally used when you want to make changes on multiple pages. • It is ideal for this condition because it facilitates you to change the look of the entire website by changing just one file. • It used the <link> tag on every pages and the <link> tag should be put inside the head section. <head> <link rel=“stylesheet” type=“text/css” href=“style.css”> </head> • The external style sheet may be written in text editor but must be saved with a .css extension.This file should not contain HTML elements
  • 10. •What style will be used when there is more than one style specified for an HTML element?
  • 11. Continued… • If there are multiple style sheets the priority level is defined as following: 1. Inline style sheet 2. Internal style sheet 3. External style sheet
  • 12. Big Problem • HTML was never intended to contain tags for formatting a web page • HTML was created to describe the content of the web page • When tags like <font> and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large websites, where fonts and color information were added to every single page, became a long and expensive process • To solve this problem, theWorld Wide Web Consortium (W3C) created CSS that removed the style formatting from the HTML page
  • 13. CSS Syntax • A CSS rule-set consists of a selector and a declaration block: H1 {color:blue; font-size:12px;} Selector Declaration Declaration Property Value Property Value
  • 14. Continued... • 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 semicolon • A CSS declaration always ends with a semicolon and declaration blocks are surrounded by curly braces
  • 15. CSS Selectors • CSS selectors are used to “find” (or select) HTML elements based on their element name, id, class, attribute and more
  • 16. Types of CSS Selectors • There are 3 types of CSS selectors • Element Selector • Id Selector • Class Selector • Child Selector • Attribute Selector
  • 17. Continued… • Element Selector • The element selector selects elements based on the element name. • Id Selector • The id selector used the id attribute of an HTML element to select a specific element. • The id of an element should be unique within a page, so the id selector is used to select one unique element. • To select an element with a specific id, write a hash character, followed by the id of the element.
  • 18. Continued… • Class Selector • The class selector selects elements with a specific class attribute. • To select elements with a specific class, write a period character, followed by the name of the class. .center {text-align: center; color: red;} • You can also specify that only specific HTML elements should be affected by a class. p. center {text-align: center; color: red;} • HTML elements can also refer to more than one class. <p class=“center large”>This paragraph refers to two classes</p>
  • 19. Continued… • Child Selector body > p {color: #000000;} • Attribute Selector • You can also apply styles to HTML elements with particular attributes • input[type=“text”] {color: #000000;}
  • 20. Grouping Selectors • If you have elements with the same style definitions, like • h1 {text-align: center; color: red;} • h2 {text-align: center; color: red;} • p {text-align: center; color: red;} • It will be better to group the selectors, to minimize the code. • To group selectors, separate each selector with a comma. • h1, h2, p {text-align: center; color: red;}
  • 21. CSS Comments • Comments are used to explain the code, and may help when you edit the source code at a later date • Comments are ignored by browsers • A CSS comment starts with /* and ends with */ • Single Line and Multiline Comments