Unit Description Example
Unit Description Example
CSS supports a number of measurements including absolute units such as inches, centimeters, points, and so on, as
well as relative measures such as percentages and em units. You need these values while specifying various
measurements in your Style rules e.g border = "1px solid red".
We have listed out all the CSS Measurement Units along with proper Examples −
Unit Description Example
ex This value defines a measurement relative to a font's x-height. The x-height is p {font-size: 24pt;
determined by the height of the font's lowercase letter x. line-height: 3ex;}
CSS uses color values to specify a color. Typically, these are used to set a color either for the foreground of an
element (i.e., its text) or else for the background of the element. They can also be used to affect the color of borders
and other decorative effects.
You can specify your color values in various formats. Following table lists all the possible formats −
Format Syntax Example
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
To Become more comfortable - Do Online Practice
CSS Colors - Short Hex Codes
This is a shorter form of the six-digit notation. In this format, each digit is replicated to arrive at an equivalent six-
digit value. For example: #6A7 becomes #66AA77.
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc Paintshop Pro, or even
using Advanced Paint Brush.
Each hexadecimal code will be preceded by a pound or hash sign '#'. Following are the examples to use
Hexadecimal notation.
Color Color HEX
#000
#F00
#0F0
#0FF
#FF0
#0FF
#F0F
#FFF
CSS Colors - RGB Values
This color value is specified using the rgb( ) property. This property takes three values, one each for red, green,
and blue. The value can be an integer between 0 and 255 or a percentage.
NOTE: All the browsers does not support rgb() property of color so it is recommended not to use it.
Following is the example to show few colors using RGB values.
Color Color RGB
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
Building Color Codes
You can build millions of color codes using our Color Code Builder. Check our HTML Color Code Builder. To use
this tool you would need a Java Enabled Browser.
Browser Safe Colors
Here is the list of 216 colors which are supposed to be most safe and computer independent colors. These colors
vary from hexa code 000000 to FFFFFF. These colors are safe to use because they ensure that all computers would
display the colors correctly when running a 256 color palette −
000000 000033 000066 000099 0000CC 0000FF
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>
<body>
</body>
</html>
It will produce the following result −
The following example demonstrates how to set the scrolling background image.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-attachment:scroll;
}.
</style>
</head>
<body>
</body>
</html>
It will produce the following result −
Shorthand Property
You can use the background property to set all the background properties at once. For example −
<p style="background:url(/images/pattern1.gif) repeat fixed;">
This parapgraph has fixed repeated background image.
</p>
This chapter teaches you how to set fonts of a content, available in an HTML element. You can set following font
properties of an element −
The font-family property is used to change the face of a font.
The font-style property is used to make a font italic or oblique.
The font-variant property is used to create a small-caps effect.
The font-weight property is used to increase or decrease how bold or light a font appears.
The font-size property is used to increase or decrease the size of a font.
The font property is used as shorthand to specify a number of other font properties.
Set the Font Family
Following is the example, which demonstrates how to set the font family of an element. Possible value could be
any font family name.
<html>
<head>
</head>
<body>
<p style="font-family:georgia,garamond,serif;">
This text is rendered in either georgia, garamond, or the default serif font
depending on which font you have at your system.
</p>
</body>
</html>
It will produce the following result −
Set the Font Style
Following is the example, which demonstrates how to set the font style of an element. Possible values are normal,
italic and oblique.
<html>
<head>
</head>
<body>
<p style="font-style:italic;">
This text will be rendered in italic style
</p>
</body>
</html>
It will produce the following result −
Set the Font Variant
The following example demonstrates how to set the font variant of an element. Possible values are normal and
small-caps.
<html>
<head>
</head>
<body>
<p style="font-variant:small-caps;">
This text will be rendered as small caps
</p>
</body>
</html>
It will produce the following result −
Set the Font Weight
The following example demonstrates how to set the font weight of an element. The font-weight property provides
the functionality to specify how bold a font is. Possible values could be normal, bold, bolder, lighter, 100, 200,
300, 400, 500, 600, 700, 800, 900.
<html>
<head>
</head>
<body>
<p style="font-weight:bold;">This font is bold.</p>
<p style="font-weight:bolder;">This font is bolder.</p>
<p style="font-weight:500;">This font is 500 weight.</p>
</body>
</html>
It will produce the following result −
Set the Font Size
The following example demonstrates how to set the font size of an element. The font-size property is used to
control the size of fonts. Possible values could be xx-small, x-small, small, medium, large, x-large, xx-large,
smaller, larger, size in pixels or in %.
<html>
<head>
</head>
<body>
<p style="font-size:20px;">This font size is 20 pixels</p>
<p style="font-size:small;">This font size is small</p>
<p style="font-size:large;">This font size is large</p>
</body>
</html>
It will produce the following result −
Set the Font Size Adjust
The following example demonstrates how to set the font size adjust of an element. This property enables you to
adjust the x-height to make fonts more legible. Possible value could be any number.
<html>
<head>
</head>
<body>
<p style="font-size-adjust:0.61;">
This text is using a font-size-adjust value.
</p>
</body>
</html>
It will produce the following result −
Set the Font Stretch
The following example demonstrates how to set the font stretch of an element. This property relies on the user's
computer to have an expanded or condensed version of the font being used.
Possible values could be normal, wider, narrower, ultra-condensed, extra-condensed, condensed, semi-condensed,
semi-expanded, expanded, extra-expanded, ultra-expanded.
<html>
<head>
</head>
<body>
<p style="font-stretch:ultra-expanded;">
If this doesn't appear to work, it is likely that your computer doesn't have a
condensed or expanded version of the font being used.
</p>
</body>
</html>
It will produce the following result −
Shorthand Property
You can use the font property to set all the font properties at once. For example −
<html>
<head>
</head>
<body>
<p style="font:italic small-caps bold 15px georgia;">
Applying all the properties on the text at once.
</p>
</body>
</html>
It will produce the following result −
This chapter teaches you how to manipulate text using CSS properties. You can set following text properties of an
element −
The color property is used to set the color of a text.
The direction property is used to set the text direction.
The letter-spacing property is used to add or subtract space between the letters that make up a word.
The word-spacing property is used to add or subtract space between the words of a sentence.
The text-indent property is used to indent the text of a paragraph.
The text-align property is used to align the text of a document.
The text-decoration property is used to underline, overline, and strikethrough text.
The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.
The white-space property is used to control the flow and formatting of text.
The text-shadow property is used to set the text shadow around a text.
Set the Text Color
The following example demonstrates how to set the text color. Possible value could be any color name in any valid
format.
<html>
<head>
</head>
<body>
<p style="color:red;">
This text will be written in red.
</p>
</body>
</html>
It will produce the following result −
Set the Text Direction
The following example demonstrates how to set the direction of a text. Possible values are ltr or rtl.
<html>
<head>
</head>
<body>
<p style="direction:rtl;">
This text will be renedered from right to left
</p>
</body>
</html>
It will produce the following result −
Set the Space between Characters
The following example demonstrates how to set the space between characters. Possible values are normal or a
number specifying space..
<html>
<head>
</head>
<body>
<p style="letter-spacing:5px;">
This text is having space between letters.
</p>
</body>
</html>
It will produce the following result −
Set the Space between Words
The following example demonstrates how to set the space between words. Possible values are normal or a number
specifying space.
<html>
<head>
</head>
<body>
<p style="word-spacing:5px;">
This text is having space between words.
</p>
</body>
</html>
It will produce the following result −
Set the Text Indent
The following example demonstrates how to indent the first line of a paragraph. Possible values are % or a number
specifying indent space.
<html>
<head>
</head>
<body>
<p style="text-indent:1cm;">
This text will have first line indented by 1cm and this line will remain at
its actual position this is done by CSS text-indent property.
</p>
</body>
</html>
It will produce the following result −
Set the Text Alignment
The following example demonstrates how to align a text. Possible values are left, right, center, justify.
<html>
<head>
</head>
<body>
<p style="text-align:right;">
This will be right aligned.
</p>
<p style="text-align:center;">
This will be center aligned.
</p>
<p style="text-align:left;">
This will be left aligned.
</p>
</body>
</html>
It will produce the following result −
Decorating the Text
The following example demonstrates how to decorate a text. Possible values are none, underline, overline, line-
through, blink.
<html>
<head>
</head>
<body>
<p style="text-decoration:underline;">
This will be underlined
</p>
<p style="text-decoration:line-through;">
This will be striked through.
</p>
<p style="text-decoration:overline;">
This will have a over line.
</p>
<p style="text-decoration:blink;">
This text will have blinking effect
</p>
</body>
</html>
It will produce the following result &minnus;
Set the Text Cases
The following example demonstrates how to set the cases for a text. Possible values are none, capitalize,
uppercase, lowercase.
<html>
<head>
</head>
<body>
<p style="text-transform:capitalize;">
This will be capitalized
</p>
<p style="text-transform:uppercase;">
This will be in uppercase
</p>
<p style="text-transform:lowercase;">
This will be in lowercase
</p>
</body>
</html>
It will produce the following result:
Set the White Space between Text
The following example demonstrates how white space inside an element is handled. Possible values are normal,
pre, nowrap.
<html>
<head>
</head>
<body>
<p style="white-space:pre;">
This text has a line break and the white-space pre setting tells the browser to honor
it just like the HTML pre tag.</p>
</body>
</html>
It will produce the following result −
Set the Text Shadow
The following example demonstrates how to set the shadow around a text. This may not be supported by all the
browsers.
<html>
<head>
</head>
<body>
<p style="text-shadow:4px 4px 8px blue;">
If your browser supports the CSS text-shadow property, this text will have a blue shadow.
</p>
</body>
</html>
It will produce the following result −
Images play an important role in any webpage. Though it is not recommended to include a lot of images, but it is
still important to use good images wherever required.
CSS plays a good role to control image display. You can set the following image properties using CSS.
The border property is used to set the width of an image border.
The height property is used to set the height of an image.
The width property is used to set the width of an image.
The -moz-opacity property is used to set the opacity of an image.
The Image Border Property
The border property of an image is used to set the width of an image border. This property can have a value in
length or in %.
A width of zero pixels means no border.
Here is the example −
<html>
<head>
</head>
<body>
<img style="border:0px;" src="/css/images/logo.png" />
<br />
<img style="border:3px dashed red;" src="/css/images/logo.png" />
</body>
</html>
It will produce the following result −
The Image Height Property
The height property of an image is used to set the height of an image. This property can have a value in length or in
%. While giving value in %, it applies it in respect of the box in which an image is available.
Here is an example −
<html>
<head>
</head>
<body>
<img style="border:1px solid red; height:100px;" src="/css/images/logo.png" />
<br />
<img style="border:1px solid red; height:50%;" src="/css/images/logo.png" />
</body>
</html>
It will produce the following result −
The Image Width Property
The width property of an image is used to set the width of an image. This property can have a value in length or in
%. While giving value in %, it applies it in respect of the box in which an image is available.
Here is an example −
<html>
<head>
</head>
<body>
<img style="border:1px solid red; width:150px;" src="/css/images/logo.png" />
<br />
<img style="border:1px solid red; width:100%;" src="/css/images/logo.png" />
</body>
</html>
It will produce the following result −
The -moz-opacity Property
The -moz-opacity property of an image is used to set the opacity of an image. This property is used to create a
transparent image in Mozilla. IE uses filter:alpha(opacity=x) to create transparent images.
In Mozilla (-moz-opacity:x) x can be a value from 0.0 - 1.0. A lower value makes the element more transparent
(The same things goes for the CSS3-valid syntax opacity:x).
In IE (filter:alpha(opacity=x)) x can be a value from 0 - 100. A lower value makes the element more transparent.
Here is an example −
<html>
<head>
</head>
<body>
<img style="border:1px solid red;-moz-opacity:0.4;filter:alpha(opacity=40);" src="/css/images/logo.png" />
</body>
</html>
It will produce the following result −
This chapter teaches you how to set different properties of a hyper link using CSS. You can set following
properties of a hyper link −
We will revisit the same properties when we will discuss Pseudo-Classes of CSS.
The :link signifies unvisited hyperlinks.
The :visited signifies visited hyperlinks.
The :hover signifies an element that currently has the user's mouse pointer hovering over it.
The :active signifies an element on which the user is currently clicking.
Usually, all these properties are kept in the header part of the HTML document.
Remember a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective. Also,
a:active MUST come after a:hover in the CSS definition as follows −
<style type="text/css">
a:link {color: #000000}
a:visited {color: #006600}
a:hover {color: #FFCC00}
a:active {color: #FF00CC}
</style>
Now, we will see how to use these properties to give different effects to hyperlinks.
Set the Color of Links
The following example demonstrates how to set the link color. Possible values could be any color name in any
valid format.
<html>
<head>
<style type="text/css">
a:link {color:#000000}
</style>
</head>
<body>
<a href="">Link</a>
</body>
</html>
It will produce the following black link:
Set the Color of Visited Links
The following example demonstrates how to set the color of visited links. Possible values could be any color name
in any valid format.
<html>
<head>
<style type="text/css">
a:visited {color: #006600}
</style>
</head>
<body>
<a href=""> link</a>
</body>
</html>
It will produce the following link. Once you will click this link, it will change its color to green.
Change the Color of Links when Mouse is Over
The following example demonstrates how to change the color of links when we bring a mouse pointer over that
link. Possible values could be any color name in any valid format.
<html>
<head>
<style type="text/css">
a:hover {color: #FFCC00}
</style>
</head>
<body>
<a href="">Link</a>
</body>
</html>
It will produce the following link. Now, you bring your mouse over this link and you will see that it changes its
color to yellow.
Change the Color of Active Links
The following example demonstrates how to change the color of active links. Possible values could be any color
name in any valid format.
<html>
<head>
<style type="text/css">
a:active {color: #FF00CC}
</style>
</head>
<body>
<a href="">Link</a>
</body>
</html>
It will produce the following link. It will change its color to pink when the user clicks it.
This tutorial will teach you how to set different properties of an HTML table using CSS. You can set
following properties of a table −
The border-collapse specifies whether the browser should control the appearance of the adjacent borders
that touch each other or whether each cell should maintain its style.
The border-spacing specifies the width that should appear between table cells.
The caption-side captions are presented in the <caption> element. By default, these are rendered above the
table in the document. You use the caption-side property to control the placement of the table caption.
The empty-cells specifies whether the border should be shown if a cell is empty.
The table-layout allows browsers to speed up layout of a table by using the first width properties it comes
across for the rest of a column rather than having to load the whole table before rendering it.
Now, we will see how to use these properties with examples.
The border-collapse Property:
This property can have two values collapse and separate. The following example uses both the values:
<html>
<head>
<style type="text/css">
table.one {border-collapse:collapse;}
table.two {border-collapse:separate;}
td.a {
border-style:dotted;
border-width:3px;
border-color:#000000;
padding: 10px;
}
td.b {
border-style:solid;
border-width:3px;
border-color:#333333;
padding:10px;
}
</style>
</head>
<body>
<table class="one">
<caption>Collapse Border Example</caption>
<tr><td class="a"> Cell A Collapse Example</td></tr>
<tr><td class="b"> Cell B Collapse Example</td></tr>
</table>
<br />
<table class="two">
<caption>Separate Border Example</caption>
<tr><td class="a"> Cell A Separate Example</td></tr>
<tr><td class="b"> Cell B Separate Example</td></tr>
</table>
</body>
</html>
It will produce the following result −
The border-spacing Property
The border-spacing property specifies the distance that separates adjacent cells'. borders. It can take either one or
two values; these should be units of length.
If you provide one value, it will applies to both vertical and horizontal borders. Or you can specify two values, in
which case, the first refers to the horizontal spacing and the second to the vertical spacing −
NOTE − Unfortunately, this property does not work in Netscape 7 or IE 6.
<style type="text/css">
/* If you provide one value */
table.example {border-spacing:10px;}
/* This is how you can provide two values */
table.example {border-spacing:10px; 15px;}
</style>
Now let's modify the previous example and see the effect −
<html>
<head>
<style type="text/css">
table.one {
border-collapse:separate;
width:400px;
border-spacing:10px;
}
table.two {
border-collapse:separate;
width:400px;
border-spacing:10px 50px;
}
</style>
</head>
<body>
</body>
</html>
It will produce the following result −
The caption-side Property
The caption-side property allows you to specify where the content of a <caption> element should be placed in
relationship to the table. The table that follows lists the possible values.
This property can have one of the four values top, bottom, left or right. The following example uses each value.
NOTE: These properties may not work with your IE Browser.
<html>
<head>
<style type="text/css">
caption.top {caption-side:top}
caption.bottom {caption-side:bottom}
caption.left {caption-side:left}
caption.right {caption-side:right}
</style>
</head>
<body>
</body>
</html>
It will produce the following result −
The empty-cells Property
The empty-cells property indicates whether a cell without any content should have a border displayed.
This property can have one of the three values - show, hide or inherit.
Here is the empty-cells property used to hide borders of empty cells in the <table> element.
<html>
<head>
<style type="text/css">
table.empty{
width:350px;
border-collapse:separate;
empty-cells:hide;
}
td.empty{
padding:5px;
border-style:solid;
border-width:1px;
border-color:#999999;
}
</style>
</head>
<body>
<table class="empty">
<tr>
<th></th>
<th>Title one</th>
<th>Title two</th>
</tr>
<tr>
<th>Row Title</th>
<td class="empty">value</td>
<td class="empty">value</td>
</tr>
<tr>
<th>Row Title</th>
<td class="empty">value</td>
<td class="empty"></td>
</tr>
</table>
</body>
</html>
It will produce the following result −
The table-layout Property
The table-layout property is supposed to help you control how a browser should render or lay out a table.
This property can have one of the three values: fixed, auto or inherit.
The following example shows the difference between these properties.
NOTE − This property is not supported by many browsers so do not rely on this property.
<html>
<head>
<style type="text/css">
table.auto {
table-layout: auto
}
table.fixed{
table-layout: fixed
}
</style>
</head>
<body>
</body>
</html>
It will produce the following result −
The border properties allow you to specify how the border of the box representing an element should look. There
are three properties of a border you can change:
The border-color specifies the color of a border.
The border-style specifies whether a border should be solid, dashed line, double line, or one of the other
possible values.
The border-width specifies the width of a border.
Now, we will see how to use these properties with examples.
The border-color Property
The border-color property allows you to change the color of the border surrounding an element. You can
individually change the color of the bottom, left, top and right sides of an element's border using the properties −
border-bottom-color changes the color of bottom border.
border-top-color changes the color of top border.
border-left-color changes the color of left border.
border-right-color changes the color of right border.
The following example shows the effect of all these properties −
<html>
<head>
<style type="text/css">
p.example1{
border:1px solid;
border-bottom-color:#009900; /* Green */
border-top-color:#FF0000; /* Red */
border-left-color:#330000; /* Black */
border-right-color:#0000CC; /* Blue */
}
p.example2{
border:1px solid;
border-color:#009900; /* Green */
}
</style>
</head>
<body>
<p class="example1">
This example is showing all borders in different colors.
</p>
<p class="example2">
This example is showing all borders in green color only.
</p>
</body>
</html>
It will produce the following result −
The border-style Property
The border-style property allows you to select one of the following styles of border −
none: No border. (Equivalent of border-width:0;)
solid: Border is a single solid line.
dotted: Border is a series of dots.
dashed: Border is a series of short lines.
double: Border is two solid lines.
groove: Border looks as though it is carved into the page.
ridge: Border looks the opposite of groove.
inset: Border makes the box look like it is embedded in the page.
outset: Border makes the box look like it is coming out of the canvas.
hidden: Same as none, except in terms of border-conflict resolution for table elements.
You can individually change the style of the bottom, left, top, and right borders of an element using the
following properties −
border-bottom-style changes the style of bottom border.
border-top-style changes the style of top border.
border-left-style changes the style of left border.
border-right-style changes the style of right border.
The following example shows all these border styles −
<html>
<head>
</head>
<body>.
<p style="border-width:4px; border-style:none;">
This is a border with none width.
</p>
<p style="border-width:4px;border-top-style:solid;
border-bottom-style:dashed; border-left-style:groove; border-right-style:double;">
This is a a border with four different styles.
</p>
</body>
</html>
It will produce the following result −
The border-width Property −
The border-width property allows you to set the width of an element borders. The value of this property could be
either a length in px, pt or cm or it should be set to thin, medium or thick.
You can individually change the width of the bottom, top, left, and right borders of an element using the
following properties −
border-bottom-width changes the width of bottom border.
border-top-width changes the width of top border.
border-left-width changes the width of left border.
border-right-width changes the width of right border.
The following example shows all these border width −
<html>
<head>
</head>
<body>
<p style="border-width:4px; border-style:solid;">
This is a solid border whose width is 4px.
</p>
<p style="border-bottom-width:4px;border-top-width:10px;
border-left-width: 2px;border-right-width:15px;border-style:solid;">
This is a a border with four different width.
</p>
</body>
</html>
It will produce the following result −
Border Properties Using Shorthand
The border property allows you to specify color, style, and width of lines in one property −
The following example shows how to use all the three properties into a single property. This is the most frequently
used property to set border around any element.
<html>
<head>
</head>
<body>
<p style="border:4px solid red;">
This example is showing shorthand property for border.
</p>
</body>
</html>
It will produce the following result −
The margin property defines the space around an HTML element. It is possible to use negative values to overlap
content.
The values of the margin property are not inherited by the child elements. Remember that the adjacent vertical
margins (top and bottom margins) will collapse into each other so that the distance between the blocks is not the
sum of the margins, but only the greater of the two margins or the same size as one margin if both are equal.
We have the following properties to set an element margin.
The margin specifies a shorthand property for setting the margin properties in one declaration.
The margin-bottom specifies the bottom margin of an element.
The margin-top specifies the top margin of an element.
The margin-left specifies the left margin of an element.
The margin-right specifies the right margin of an element.
Now, we will see how to use these properties with examples.
The Margin Property
The margin property allows you set all of the properties for the four margins in one declaration. Here is the syntax
to set margin around a paragraph −
Here is an example −
<html>
<head>
</head>
<body>
<p style="margin: 15px; border:1px solid black;">
all four margins will be 15px
</p>
</html>
It will produce the following result −
The margin-bottom Property
The margin-bottom property allows you set bottom margin of an element. It can have a value in length, % or auto.
Here is an example −
<html>
<head>
</head>
<body>
<p style="margin-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom margin.
</p>
none NA
<body>
<ul style="list-style-type:circle;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ul style="list-style-type:square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol style="list-style-type:decimal;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
<ol style="list-style-type:lower-alpha;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
<ol style="list-style-type:lower-roman;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
</body>
</html>
It will produce the following result −
The list-style-position Property
The list-style-position property indicates whether the marker should appear inside or outside of the box containing
the bullet points. It can have one the two values −
Value Description
none NA
inside If the text goes onto a second line, the text will wrap underneath the marker. It will also appear
indented to where the text would have started if the list had a value of outside.
outside If the text goes onto a second line, the text will be aligned with the start of the first line (to the right
of the bullet).
Here is an example −
<html>
<head>
</head>
<body>
<ul style="list-style-type:circle; list-style-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ul style="list-style-type:square;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol style="list-style-type:decimal;list-style-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
<ol style="list-style-type:lower-alpha;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
</body>
</html>
It will produce the following result −
The list-style-image Property
The list-style-image allows you to specify an image so that you can use your own bullet style. The syntax is similar
to the background-image property with the letters url starting the value of the property followed by the URL in
brackets. If it does not find the given image then default bullets are used.
Here is an example −
<html>
<head>
</head>
<body>
<ul>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
</body>
</html>
It will produce the following result −
The list-style Property
The list-style allows you to specify all the list properties into a single expression. These properties can appear in
any order.
Here is an example −
<html>
<head>
</head>
<body>
<ul style="list-style: inside square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
</html>
It will produce the following result −
The marker-offset Property
The marker-offset property allows you to specify the distance between the marker and the text relating to that
marker. Its value should be a length as shown in the following example −
Unfortunately, this property is not supported in IE 6 or Netscape 7.
Here is an example −
<html>
<head>
</head>
<body>
<ul style="list-style: inside square; marker-offset:2em;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
</html>
It will produce the following result −
The padding property allows you to specify how much space should appear between the content of an element and
its border −
The value of this attribute should be either a length, a percentage, or the word inherit. If the value is inherit, it will
have the same padding as its parent element. If a percentage is used, the percentage is of the containing box.
The following CSS properties can be used to control lists. You can also set different values for the padding on each
side of the box using the following properties −
The padding-bottom specifies the bottom padding of an element.
The padding-top specifies the top padding of an element.
The padding-left specifies the left padding of an element.
The padding-right specifies the right padding of an element.
The padding serves as shorthand for the preceding properties.
Now, we will see how to use these properties with examples.
The padding-bottom Property
The padding-bottom property sets the bottom padding (space) of an element. This can take a value in terms of
length of %.
Here is an example −
<html>
<head>
</head>
<body>
<p style="padding-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom padding
</p>
</html>
It will produce the following result:
The padding-top Property
The padding-top property sets the top padding (space) of an element. This can take a value in terms of length of %.
Here is an example −
<html>
<head>
</head>
<body>
<p style="padding-top: 15px; border:1px solid black;">
This is a paragraph with a specified top padding
</p>
</html>
It will produce the following result −
The padding-left Property
The padding-left property sets the left padding (space) of an element. This can take a value in terms of length of %.
Here is an example −
<html>
<head>
</head>
<body>
<p style="padding-left: 15px; border:1px solid black;">
This is a paragraph with a specified left padding
</p>
</html>
It will produce the following result −
The padding-right Property
The padding-right property sets the right padding (space) of an element. This can take a value in terms of length of
%.
Here is an example −
<html>
<head>
</head>
<body>
<p style="padding-right: 15px; border:1px solid black;">
This is a paragraph with a specified right padding
</p>
</html>
It will produce the following result −
The Padding Property
The padding property sets the left, right, top and bottom padding (space) of an element. This can take a value in
terms of length of %.
Here is an example −
<html>
<head>
</head>
<body>
<p style="padding: 15px; border:1px solid black;">
all four padding will be 15px
</p>
</html>
It will produce the following result −
The cursor property of CSS allows you to specify the type of cursor that should be displayed to the user.
One good usage of this property is in using images for submit buttons on forms. By default, when a cursor hovers
over a link, the cursor changes from a pointer to a hand. However, it does not change form for a submit button on a
form. Therefore, whenever someone hovers over an image that is a submit button, it provides a visual clue that the
image is clickable.
The following table shows the possible values for the cursor property −
Value Description
auto Shape of the cursor depends on the context area it is over. For example, an 'I' over text, a
'hand' over a link, and so on.
default An arrow
e-resize The cursor indicates that an edge of a box is to be moved right (east).
ne-resize The cursor indicates that an edge of a box is to be moved up and right (north/east).
nw-resize The cursor indicates that an edge of a box is to be moved up and left (north/west).
se-resize The cursor indicates that an edge of a box is to be moved down and right (south/east).
sw-resize The cursor indicates that an edge of a box is to be moved down and left (south/west).
s-resize The cursor indicates that an edge of a box is to be moved down (south).
w-resize The cursor indicates that an edge of a box is to be moved left (west).
help A question mark or balloon, ideal for use over help buttons.
<body>
<p>Move the mouse over the words to see the cursor change:</p>
<div style="cursor:auto">Auto</div>
<div style="cursor:crosshair">Crosshair</div>
<div style="cursor:default">Default</div>
<div style="cursor:pointer">Pointer</div>
<div style="cursor:move">Move</div>
<div style="cursor:e-resize">e-resize</div>
<div style="cursor:ne-resize">ne-resize</div>
<div style="cursor:nw-resize">nw-resize</div>
<div style="cursor:n-resize">n-resize</div>
<div style="cursor:se-resize">se-resize</div>
<div style="cursor:sw-resize">sw-resize</div>
<div style="cursor:s-resize">s-resize</div>
<div style="cursor:w-resize">w-resize</div>
<div style="cursor:text">text</div>
<div style="cursor:wait">wait</div>
<div style="cursor:help">help</div>
</body>
</html>
It will produce the following result −
Outlines are very similar to borders, but there are few major differences as well −
An outline does not take up space.
Outlines do not have to be rectangular.
Outline is always the same on all sides; you cannot specify different values for different sides of an
element.
NOTE − The outline properties are not supported by IE 6 or Netscape 7.
You can set the following outline properties using CSS.
The outline-width property is used to set the width of the outline.
The outline-style property is used to set the line style for the outline.
The outline-color property is used to set the color of the outline.
The outline property is used to set all the above three properties in a single statement.
The outline-width Property
The outline-width property specifies the width of the outline to be added to the box. Its value should be a length or
one of the values thin, medium, or thick, just like the border-width attribute.
A width of zero pixels means no outline.
Here is an example −
<html>
<head>
</head>
<body>
<p style="outline-width:thin; outline-style:solid;">
This text is having thin outline.
</p>
<br />
</html>
It will produce the following result −
The outline-style Property
The outline-style property specifies the style for the line (solid, dotted, or dashed) that goes around an element. It
can take one of the following values −
none: No border. (Equivalent of outline-width:0;)
solid: Outline is a single solid line.
dotted: Outline is a series of dots.
dashed: Outline is a series of short lines.
double: Outline is two solid lines.
groove: Outline looks as though it is carved into the page.
ridge: Outline looks the opposite of groove.
inset: Outline makes the box look like it is embedded in the page.
outset: Outline makes the box look like it is coming out of the canvas.
hidden: Same as none.
Here is an example −
<html>
<head>
</head>
<body>
<p style="outline-width:thin; outline-style:solid;">
This text is having thin solid outline.
</p>
<br />
<p style="outline-width:5px;outline-style:dotted;">
This text is having 5x dotted outline.
</p>
</body>
</html>
It will produce the following result −
The outline-color Property
The outline-color property allows you to specify the color of the outline. Its value should either be a color name, a
hex color, or an RGB value, as with the color and border-color properties.
Here is an example −
<html>
<head>
</head>
<body>
<p style="outline-width:thin; outline-style:solid;outline-color:red">
This text is having thin solid red outline.
</p>
<br />
<p style="outline-width:5px;outline-style:dotted;outline-color:rgb(13,33,232)">
This text is having 5x dotted blue outline.
</p>
</body>
</html>
It will produce the following result −
The outline Property
The outline property is a shorthand property that allows you to specify values for any of the
three properties discussed previously in any order but in a single statement.
Here is an example −
<html>
<head>
</head>
<body>
<p style="outline:thin solid red;">
This text is having thin solid red outline.
</p>
<br />
</html>
It will produce the following result −
You have seen the border that surrounds every box ie. element, the padding that can appear inside each box and the
margin that can go around them. In this tutorial we will how we can change the dimensions of boxes.
We have the following properties that allow you to control the dimensions of a box.
The height property is used to set the height of a box.
The width property is used to set the width of a box.
The line-height property is used to set the height of a line of text.
The max-height property is used to set a maximum height that a box can be.
The min-height property is used to set the minimum height that a box can be.
The max-width property is used to set the maximum width that a box can be.
The min-width property is used to set the minimum width that a box can be.
The Height and Width Properties
The height and width properties allow you to set the height and width for boxes. They can take values of a length, a
percentage, or the keyword auto.
Here is an example −
<html>
<head>
</head>
<body>
<p style="width:400px; height:100px; border:1px solid red; padding:5px; margin:10px;">
This paragraph is 400pixels wide and 100 pixels high
</p>
</body>
</html>
It will produce the following result −
The line-height Property
The line-height property allows you to increase the space between lines of text. The value of the line-height
property can be a number, a length, or a percentage.
Here is an example −
<html>
<head>
</head>
<body>
<p style="width:400px; height:100px; border:1px solid red; padding:5px; margin:10px; line-height:30px;">
This paragraph is 400pixels wide and 100 pixels high and here line height is 30pixels.
This paragraph is 400 pixels wide and 100 pixels high and here line height is 30pixels.
</p>
</body>
</html>
It will produce the following result −
The max-height Property
The max-height property allows you to specify maximum height of a box. The value of the max-height property
can be a number, a length, or a percentage.
NOTE − This property does not work in either Netscape 7 or IE 6.
Here is an example −
<html>
<head>
</head>
<body>
<p style="width:400px; max-height:10px; border:1px solid red; padding:5px; margin:10px;">
This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
</p>
<br>
<br>
<br>
<img alt="logo" src="/css/images/logo.png" width="195" height="84" />
</body>
</html>
It will produce the following result −
The min-height Property
The min-height property allows you to specify minimum height of a box. The value of the min-height property can
be a number, a length, or a percentage.
NOTE − This property does not work in either Netscape 7 or IE 6.
Here is an example −
<html>
<head>
</head>
<body>
<p style="width:400px; min-height:200px; border:1px solid red; padding:5px; margin:10px;">
This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
</p>
<img alt="logo" src="/css/images/logo.png" width="95" height="84" />
</body>
</html>
It will produce the following result −
The max-width Property
The max-width property allows you to specify maximum width of a box. The value of the max-width property can
be a number, a length, or a percentage.
NOTE − This property does not work in either Netscape 7 or IE 6.
Here is an example −
<html>
<head>
</head>
<body>
<p style="max-width:100px; height:200px; border:1px solid red; padding:5px; margin:10px;">
This paragraph is 200px high and max width is 100px
This paragraph is 200px high and max width is 100px
</p>
<img alt="logo" src="/css/images/logo.png" width="95" height="84" />
</body>
</html>
It will produce the following result −
The min-width Property
The min-width property allows you to specify minimum width of a box. The value of the min-width property can
be a number, a length, or a percentage.
NOTE − This property does not work in either Netscape 7 or IE 6.
Here is an example −
<html>
<head>
</head>
<body>
<p style="min-width:400px; height:100px; border:1px solid red; padding:5px; margin:10px;">
This paragraph is 100px high and min width is 400px
This paragraph is 100px high and min width is 400px
<img alt="logo" src="/css/images/css.gif" width="95" height="84" />
</body>
</html>
It will produce the following result −
You have seen the border that surrounds every box ie. element, the padding that can appear inside each box and the
margin that can go around them. In this tutorial we will how we can change the dimensions of boxes.
We have the following properties that allow you to control the dimensions of a box.
The height property is used to set the height of a box.
The width property is used to set the width of a box.
The line-height property is used to set the height of a line of text.
The max-height property is used to set a maximum height that a box can be.
The min-height property is used to set the minimum height that a box can be.
The max-width property is used to set the maximum width that a box can be.
The min-width property is used to set the minimum width that a box can be.
There may be a case when an element's content might be larger than the amount of space allocated to it.
For example, given width and height properties do not allow enough room to accommodate the content of
the element.
CSS provides a property called overflow which tells the browser what to do if the box's contents is larger
than the box itself. This property can take one of the following values −
Value Description
visible Allows the content to overflow the borders of its containing element.
hidden The content of the nested element is simply cut off at the border of the containing element and no
scrollbars is visible.
scroll The size of the containing element does not change, but the scrollbars are added to allow the user to
scroll to see the content.
auto The purpose is the same as scroll, but the scrollbar will be shown only if the content does overflow.
Here is an example −
<html>
<head>
</head>
<style type="text/css">
.scroll{
display:block;
border: 1px solid red;
padding:5px;
margin-top:5px;
width:300px;
height:50px;
overflow:scroll;
}
.auto{
display:block;
border: 1px solid red;
padding:5px;
margin-top:5px;
width:300px;
height:50px;
overflow:auto;
}
</style>
<body>
<p>Example of scroll value:</p>
<div class="scroll">
I am going to keep lot of content here just to show you how scrollbars works if there is an overflow in
an
element box. This provides your horizontal as well as vertical scrollbars.
</div>
<br />
<p>Example of auto value:</p>
<div class="auto">
I am going to keep lot of content here just to show you how scrollbars works if there is an overflow in
an element box.
This provides your horizontal as well as vertical scrollbars.
</div>
</body>
</html>
It will produce the following result −