You are on page 1of 3

7/21/2014 CSS3 Backgrounds

http://www.w3schools.com/css/css3_backgrounds.asp 1/3
REFERENCES | EXAMPLES | FORUM
CSS Tutorial
CSS HOME
CSS Introduction
CSS Syntax
CSS Selectors
CSS How To
CSS Backgrounds
CSS Text
CSS Fonts
CSS Links
CSS Lists
CSS Tables
CSS Box Model
CSS Border
CSS Outline
CSS Margin
CSS Padding
CSS Dimension
CSS Display
CSS Positioning
CSS Floating
CSS Align
CSS Combinators
CSS Pseudo-class
CSS Pseudo-element
CSS Navigation Bar
CSS Image Gallery
CSS Image Opacity
CSS Image Sprites
CSS Media Types
CSS Attr Selectors
CSS3 Tutorial
CSS3 Introduction
CSS3 Borders
CSS3 Backgrounds
CSS3 Gradients
CSS3 Text Effects
CSS3 Fonts
CSS3 2D Transforms
CSS3 3D Transforms
CSS3 Transitions
CSS3 Animations
CSS3 Multiple Columns
CSS3 User Interface
CSS Summary
CSS Examples
CSS Examples
CSS Quiz
CSS Certificate
CSS References
CSS Reference
CSS Selectors
CSS Reference Aural
CSS Web Safe Fonts
CSS Units
CSS Colors
CSS Color Values
CSS Color Names
CSS Color HEX
Previous Next Chapter
CSS3 Backgrounds
CSS3 Backgrounds
CSS3 contains several new background properties,
which allow greater control of the background element.
In this chapter you will learn about the following background properties:
background-size
background-origin
You will also learn how to use multiple background images.
Browser Support
The numbers in the table specifies the first browser version that fully supports the property.
Numbers followed by -webkit-, -moz-, or -o- specifies the first version that worked with a prefix.
Property
background-size 9.0 3.0
1.0 -webkit-
4.0
3.6 -moz-
4.1
3.0 -webkit-
10.0
9.5 -o-
background-origin 9.0 1.0 4.0 3.0 10.5
CSS3 The background-size Property
The background-size property specifies the size of the background image.
Before CSS3, the background image size was determined by the actual size of the image. In CSS3 it is possible to specify
the size of the background image, which allows us to re-use background images in different contexts.
You can specify the size in pixels or in percentages. If you specify the size as a percentage, the size is relative to the
width and height of the parent element.
Example 1
Resize a background image:
div {
background: url(img_flwr.gif);
background-size: 80px 60px;
background-repeat: no-repeat;
}
Try it yourself
Example 2
Stretch the background image to completely fill the content area:
div {
background: url(img_flwr.gif);
background-size: 100% 100%;
background-repeat: no-repeat;
}
Try it yourself
CSS3 The background-origin Property
The background-origin property specifies the positioning area of the background images.
Search w3schools.com:
WEB HOSTING
WEB BUILDING
W3SCHOOLS EXAMS
HTML, CSS, JavaScript,
PHP, jQuery, XML, and
ASP Certifications
SHARE THIS PAGE
WEB RESOURCES
Web Statistics
Web Validation
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
Select Language
7/21/2014 CSS3 Backgrounds
http://www.w3schools.com/css/css3_backgrounds.asp 2/3
Previous Next Chapter
The background image can be placed within the content-box, padding-box, or border-box area.
Example
Position the background image within the content-box:
div {
background: url(img_flwr.gif);
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box;
}
Try it yourself
CSS3 Multiple Background Images
CSS3 allows you to use several background images for an element.
Example
Set two background images for the body element:
body {
background: url(img_tree.gif), url(img_flwr.gif);
background-size: 100% 100%;
background-repeat: no-repeat;
}
Try it yourself
CSS3 Background Properties
Property Description CSS
background-clip Specifies the painting area of the background images 3
background-origin Specifies the positioning area of the background images 3
background-size Specifies the size of the background images 3
REPORT ERROR | HOME | TOP | PRINT | FORUM | ABOUT | ADVERTISE WITH US
Top 10 Tutorials
HTML Tutorial
HTML5 Tutorial
CSS Tutorial
CSS3 Tutorial
JavaScript Tutorial
jQuery Tutorial
SQL Tutorial
PHP Tutorial
ASP.NET Tutorial
XML Tutorial
Top 10 References
HTML/HTML5 Reference
CSS 1,2,3 Reference
CSS 3 Browser Support
JavaScript
HTML DOM
XML DOM
PHP Reference
jQuery Reference
ASP.NET Reference
HTML Colors
Top 10 Examples
HTML Examples
CSS Examples
JavaScript Examples
HTML DOM Examples
PHP Examples
jQuery Examples
XML Examples
XML DOM Examples
ASP Examples
SVG Examples
Web Certificates
HTML Certificate
HTML5 Certificate
CSS Certificate
JavaScript Certificate
jQuery Certificate
PHP Certificate
XML Certificate
ASP Certificate
Color Picker
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples
are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use,
cookie and privacy policy. Copyright 1999-2014 by Refsnes Data. All Rights Reserved.
7/21/2014 CSS3 Backgrounds
http://www.w3schools.com/css/css3_backgrounds.asp 3/3

You might also like