SlideShare a Scribd company logo
1 of 17
7
ADDING IMAGES
OVERVIEW
• Web image formats
• The img element
• Attributes for the img element
• Adding an SVG to a page
Web Image Formats
Image formats appropriate for web pages:
• PNG
• JPEG
• GIF
• SVG
• WebP (up and coming, not yet widely supported)
Bitmapped vs. Vector Formats
PNG, JPEG,
GIF, and WebP
are bitmapped
formats.
SVG is a vector
format.
The img Element
<img src="" alt="">
• Embed images on the page with the empty img element.
• The src and alt attributes are required.
• img can be used for PNG, JPEG, GIF, and SVG.
NOTE: Special markup is recommended for experimenting with cutting-
edge image formats like WebP.
The img Element (cont’d)
<p>This summer, try making pizza <img src="pizza.png" alt="">
on your grill.</p>
The img element tells the browser to make a server request for
the image and display it in its place:
The src attribute
• The value is the location (URL) of the image file.
• Use the relative pathname conventions to point to the image
on the server.
PERFORMANCE TIP: Take advantage of caching (temporary storage).
For the same image used repeatedly, using the same pathname
reduces the number of calls to the server.
<img src="/images/icon/next.png" alt="Next">
The alt Attribute
• The alt attribute provides
alternative text for those who
are not able to see it.
• It is required for every img
element in order for the HTML
to be valid.
• It is used by screen readers,
search engines, and graphical
browsers when the image fails
to load.
<p> If you're <img src="/images/smiley.png" alt="happy"> and
you know it, clap your hands.</p>
Alternative Text Tips
• Alternative text (alt text) should convey the same information and
function as the image.
• If the image is purely decorative and shouldn’t be read aloud, include
the alt attribute with an empty value:
<img src="flowers.svg" alt="">
• Consider what the alt text would sound like when read aloud by a
screen reader. Is it helpful or a hindrance?
• When an image is used as a link, the alt text serves as the linked text.
Write what you’d want the link to say, don’t just describe the image.
• Avoid starting alt text with “An image of” or “Graphic of”.
width and height Attributes
• The width and height attributes set the dimensions of the image
on the page in number of pixels.
• They help the browser maintain space for the image in the layout
while the files load.
• Don’t use width and height attributes if you are sizing the image
with style sheets or if the size changes in a responsive layout.
• If the attribute values do not match the dimensions of the image,
the image will resize and may be distorted or blurry.
<img src="flowers.svg" alt="" width="120" height="160">
Adding SVG Images
SVG images are unique:
• SVG is a vector format, made up of shapes and paths.
• Those shapes and paths are described in a text file using the
Scalable Vector Graphic markup language.
• The elements in an SVG can be styled with CSS and scripted
for interactivity.
• Because they are vector, SVGs can resize with no loss of
quality.
SVG Example
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 180">
<rect width="300" height="180" fill="purple" rx="20" ry="20"/>
<text x="40" y="114" fill="yellow" font-family="'Verdana-Bold'"
font-size="72">
hello!
</text>
</svg>
Compare the SVG source to the image. The svg element
contains a rectangle (rect element) and a text element:
Adding SVG to a Page
There are several ways to add an SVG image to a web page:
• <img> element
• <object> element
• <svg> element directly in HTML (inline SVG)
Adding SVG with the img Element
You can add an .svg file to the page with the img element:
<img src="/images/circle.svg" alt="">
PROS:
• Easy and familiar
• Universally supported
CONS:
• Can’t manipulate the SVG with scripts or styles.
• The SVG can’t contain any external resources such as
images or fonts.
Embedding SVGs with object
The content of the object element is a fallback text or image that
displays if the SVG is not supported:
<object type="image/svg+xml" data="pizza.svg">
<img src="pizza.png" alt="pizza">
</object>
PROS:
• SVG can be scripted and use eternal files (images and fonts).
CONS:
• You can’t change styles with the same CSS used for the document.
• May be buggy in some browsers.
Inline SVGs with the svg Element
You can paste the content of the SVG text file directly into the HTML
source. This is called using the SVG inline.
PROS:
• Can take full advantage of scripting and styling the SVG because
the elements in the SVG are part of the DOM for the document.
CONS:
• Code can get extremely long and unwieldy.
• Harder to maintain images embedded in the source
• Can’t take advantage of caching repeated images
• Not universally supported
Example of an Inline SVG
<p>This summer, try making pizza
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72" width="100"
height="100">
<circle fill="#D4AB00" cx="36" cy="36" r="36"/>
<circle opacity=".7" fill="#FFF" stroke="#8A291C" cx="36.1" cy="35.9"
r="31.2"/>
<circle fill="#A52C1B" cx="38.8" cy="13.5" r="4.8"/>
<circle fill="#A52C1B" cx="22.4" cy="20.9" r="4.8"/>
<circle fill="#A52C1B" cx="32" cy="37.2" r="4.8"/>
<circle fill="#A52C1B" cx="16.6" cy="39.9" r="4.8"/>
<circle fill="#A52C1B" cx="26.2" cy="53.3" r="4.8"/>
<circle fill="#A52C1B" cx="42.5" cy="27.3" r="4.8"/>
<circle fill="#A52C1B" cx="44.3" cy="55.2" r="4.8"/>
<circle fill="#A52C1B" cx="54.7" cy="42.9" r="4.8"/>
<circle fill="#A52C1B" cx="56" cy="28.3" r="4.8"/>
</svg>
on your grill.</p>

More Related Content

Similar to Chapter 7: Images

SVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilitySVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilityDennis Lembree
 
Steph's Html5 and css presentation
Steph's Html5 and css presentationSteph's Html5 and css presentation
Steph's Html5 and css presentationstephy123123
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tagJesus Obenita Jr.
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Graham Armfield
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2Graham Armfield
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2Graham Armfield
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEOCentro Web
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEOReinaldo Ferraz
 
Sadielai10x10presentation
Sadielai10x10presentationSadielai10x10presentation
Sadielai10x10presentationsadielai
 
Html images and html backgrounds
Html images and html backgroundsHtml images and html backgrounds
Html images and html backgroundsnobel mujuji
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicAkila Iroshan
 
Switch Away from Icon Fonts to SVG
Switch Away from Icon Fonts to SVGSwitch Away from Icon Fonts to SVG
Switch Away from Icon Fonts to SVGExove
 
Html 5 and CSS - Image Element
Html 5 and CSS - Image ElementHtml 5 and CSS - Image Element
Html 5 and CSS - Image ElementKempy7000
 
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin..."Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...Yandex
 
Html5 Canvas Detail
Html5 Canvas DetailHtml5 Canvas Detail
Html5 Canvas DetailNisa Soomro
 
The status of living HTML (highlights)
The status of living HTML (highlights)The status of living HTML (highlights)
The status of living HTML (highlights)ourmaninjapan
 

Similar to Chapter 7: Images (20)

SVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilitySVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader Accessibility
 
HTML Images
HTML Images HTML Images
HTML Images
 
Steph's Html5 and css presentation
Steph's Html5 and css presentationSteph's Html5 and css presentation
Steph's Html5 and css presentation
 
Before Going Vector
Before Going VectorBefore Going Vector
Before Going Vector
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tag
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
 
Sadielai10x10presentation
Sadielai10x10presentationSadielai10x10presentation
Sadielai10x10presentation
 
SVG 101
SVG 101SVG 101
SVG 101
 
Html images and html backgrounds
Html images and html backgroundsHtml images and html backgrounds
Html images and html backgrounds
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
 
Switch Away from Icon Fonts to SVG
Switch Away from Icon Fonts to SVGSwitch Away from Icon Fonts to SVG
Switch Away from Icon Fonts to SVG
 
Html 5 and CSS - Image Element
Html 5 and CSS - Image ElementHtml 5 and CSS - Image Element
Html 5 and CSS - Image Element
 
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin..."Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
 
Html5 Canvas Detail
Html5 Canvas DetailHtml5 Canvas Detail
Html5 Canvas Detail
 
Web Images, The Right Way
Web Images, The Right WayWeb Images, The Right Way
Web Images, The Right Way
 
The status of living HTML (highlights)
The status of living HTML (highlights)The status of living HTML (highlights)
The status of living HTML (highlights)
 

More from Steve Guinan

Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationSteve Guinan
 
Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Steve Guinan
 
Chapter 14: Box Model
Chapter 14: Box ModelChapter 14: Box Model
Chapter 14: Box ModelSteve Guinan
 
Chapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsChapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsSteve Guinan
 
Chapter 12: CSS Part 2
Chapter 12: CSS Part 2Chapter 12: CSS Part 2
Chapter 12: CSS Part 2Steve Guinan
 
Chapter 11: Intro to CSS
Chapter 11: Intro to CSSChapter 11: Intro to CSS
Chapter 11: Intro to CSSSteve Guinan
 
HubSpot Student Instructions
HubSpot Student InstructionsHubSpot Student Instructions
HubSpot Student InstructionsSteve Guinan
 
Ch 5: Marking up Text
Ch 5: Marking up TextCh 5: Marking up Text
Ch 5: Marking up TextSteve Guinan
 
Ch 2: How the Web Works
Ch 2: How the Web WorksCh 2: How the Web Works
Ch 2: How the Web WorksSteve Guinan
 
Ch 1: Getting Started
Ch 1: Getting StartedCh 1: Getting Started
Ch 1: Getting StartedSteve Guinan
 
Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7Steve Guinan
 
Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6Steve Guinan
 
Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5Steve Guinan
 
Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4 Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4 Steve Guinan
 
Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3 Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3 Steve Guinan
 
Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2 Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2 Steve Guinan
 
Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1Steve Guinan
 

More from Steve Guinan (20)

Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and Animation
 
Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning
 
Chapter 9: Forms
Chapter 9: FormsChapter 9: Forms
Chapter 9: Forms
 
Chapter 8: Tables
Chapter 8: TablesChapter 8: Tables
Chapter 8: Tables
 
Chapter 14: Box Model
Chapter 14: Box ModelChapter 14: Box Model
Chapter 14: Box Model
 
Chapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsChapter 13: Colors and Backgrounds
Chapter 13: Colors and Backgrounds
 
Chapter 12: CSS Part 2
Chapter 12: CSS Part 2Chapter 12: CSS Part 2
Chapter 12: CSS Part 2
 
Chapter 11: Intro to CSS
Chapter 11: Intro to CSSChapter 11: Intro to CSS
Chapter 11: Intro to CSS
 
HubSpot Student Instructions
HubSpot Student InstructionsHubSpot Student Instructions
HubSpot Student Instructions
 
Ch 6: Links
Ch 6: LinksCh 6: Links
Ch 6: Links
 
Ch 5: Marking up Text
Ch 5: Marking up TextCh 5: Marking up Text
Ch 5: Marking up Text
 
Ch 2: How the Web Works
Ch 2: How the Web WorksCh 2: How the Web Works
Ch 2: How the Web Works
 
Ch 1: Getting Started
Ch 1: Getting StartedCh 1: Getting Started
Ch 1: Getting Started
 
Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7
 
Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6
 
Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5
 
Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4 Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4
 
Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3 Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3
 
Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2 Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2
 
Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1
 

Recently uploaded

VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Personfurqan222004
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 

Recently uploaded (20)

VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Person
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 

Chapter 7: Images

  • 2. OVERVIEW • Web image formats • The img element • Attributes for the img element • Adding an SVG to a page
  • 3. Web Image Formats Image formats appropriate for web pages: • PNG • JPEG • GIF • SVG • WebP (up and coming, not yet widely supported)
  • 4. Bitmapped vs. Vector Formats PNG, JPEG, GIF, and WebP are bitmapped formats. SVG is a vector format.
  • 5. The img Element <img src="" alt=""> • Embed images on the page with the empty img element. • The src and alt attributes are required. • img can be used for PNG, JPEG, GIF, and SVG. NOTE: Special markup is recommended for experimenting with cutting- edge image formats like WebP.
  • 6. The img Element (cont’d) <p>This summer, try making pizza <img src="pizza.png" alt=""> on your grill.</p> The img element tells the browser to make a server request for the image and display it in its place:
  • 7. The src attribute • The value is the location (URL) of the image file. • Use the relative pathname conventions to point to the image on the server. PERFORMANCE TIP: Take advantage of caching (temporary storage). For the same image used repeatedly, using the same pathname reduces the number of calls to the server. <img src="/images/icon/next.png" alt="Next">
  • 8. The alt Attribute • The alt attribute provides alternative text for those who are not able to see it. • It is required for every img element in order for the HTML to be valid. • It is used by screen readers, search engines, and graphical browsers when the image fails to load. <p> If you're <img src="/images/smiley.png" alt="happy"> and you know it, clap your hands.</p>
  • 9. Alternative Text Tips • Alternative text (alt text) should convey the same information and function as the image. • If the image is purely decorative and shouldn’t be read aloud, include the alt attribute with an empty value: <img src="flowers.svg" alt=""> • Consider what the alt text would sound like when read aloud by a screen reader. Is it helpful or a hindrance? • When an image is used as a link, the alt text serves as the linked text. Write what you’d want the link to say, don’t just describe the image. • Avoid starting alt text with “An image of” or “Graphic of”.
  • 10. width and height Attributes • The width and height attributes set the dimensions of the image on the page in number of pixels. • They help the browser maintain space for the image in the layout while the files load. • Don’t use width and height attributes if you are sizing the image with style sheets or if the size changes in a responsive layout. • If the attribute values do not match the dimensions of the image, the image will resize and may be distorted or blurry. <img src="flowers.svg" alt="" width="120" height="160">
  • 11. Adding SVG Images SVG images are unique: • SVG is a vector format, made up of shapes and paths. • Those shapes and paths are described in a text file using the Scalable Vector Graphic markup language. • The elements in an SVG can be styled with CSS and scripted for interactivity. • Because they are vector, SVGs can resize with no loss of quality.
  • 12. SVG Example <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 180"> <rect width="300" height="180" fill="purple" rx="20" ry="20"/> <text x="40" y="114" fill="yellow" font-family="'Verdana-Bold'" font-size="72"> hello! </text> </svg> Compare the SVG source to the image. The svg element contains a rectangle (rect element) and a text element:
  • 13. Adding SVG to a Page There are several ways to add an SVG image to a web page: • <img> element • <object> element • <svg> element directly in HTML (inline SVG)
  • 14. Adding SVG with the img Element You can add an .svg file to the page with the img element: <img src="/images/circle.svg" alt=""> PROS: • Easy and familiar • Universally supported CONS: • Can’t manipulate the SVG with scripts or styles. • The SVG can’t contain any external resources such as images or fonts.
  • 15. Embedding SVGs with object The content of the object element is a fallback text or image that displays if the SVG is not supported: <object type="image/svg+xml" data="pizza.svg"> <img src="pizza.png" alt="pizza"> </object> PROS: • SVG can be scripted and use eternal files (images and fonts). CONS: • You can’t change styles with the same CSS used for the document. • May be buggy in some browsers.
  • 16. Inline SVGs with the svg Element You can paste the content of the SVG text file directly into the HTML source. This is called using the SVG inline. PROS: • Can take full advantage of scripting and styling the SVG because the elements in the SVG are part of the DOM for the document. CONS: • Code can get extremely long and unwieldy. • Harder to maintain images embedded in the source • Can’t take advantage of caching repeated images • Not universally supported
  • 17. Example of an Inline SVG <p>This summer, try making pizza <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72" width="100" height="100"> <circle fill="#D4AB00" cx="36" cy="36" r="36"/> <circle opacity=".7" fill="#FFF" stroke="#8A291C" cx="36.1" cy="35.9" r="31.2"/> <circle fill="#A52C1B" cx="38.8" cy="13.5" r="4.8"/> <circle fill="#A52C1B" cx="22.4" cy="20.9" r="4.8"/> <circle fill="#A52C1B" cx="32" cy="37.2" r="4.8"/> <circle fill="#A52C1B" cx="16.6" cy="39.9" r="4.8"/> <circle fill="#A52C1B" cx="26.2" cy="53.3" r="4.8"/> <circle fill="#A52C1B" cx="42.5" cy="27.3" r="4.8"/> <circle fill="#A52C1B" cx="44.3" cy="55.2" r="4.8"/> <circle fill="#A52C1B" cx="54.7" cy="42.9" r="4.8"/> <circle fill="#A52C1B" cx="56" cy="28.3" r="4.8"/> </svg> on your grill.</p>